From 9d60b3d95d49c1097ceeb641f857fe724c4d9cab Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Mon, 7 Aug 2017 16:22:14 +0100 Subject: fixed -- correct execution order of scorsh commands --- types.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'types.go') diff --git a/types.go b/types.go index 795e82f..de81e65 100644 --- a/types.go +++ b/types.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "golang.org/x/crypto/openpgp" + "os" ) // error constants @@ -39,6 +40,16 @@ type commandCfg struct { Actions []action `yaml:"c_actions"` } +type commandState struct { + Env []string + Args []string +} + +type command struct { + commandCfg + commandState +} + // workerCfg represents the static configuration of a worker type workerCfg struct { Name string `yaml:"w_name"` @@ -157,3 +168,30 @@ func (msg *clientMsg) String() string { return buff.String() } + +func (cmd *command) setEnvironment(msg *spoolMsg, commitID, author, committer string) { + + env := os.Environ() + env = append(env, fmt.Sprintf("SCORSH_REPO=%s", msg.Repo)) + env = append(env, fmt.Sprintf("SCORSH_BRANCH=%s", msg.Branch)) + env = append(env, fmt.Sprintf("SCORSH_OLDREV=%s", msg.OldRev)) + env = append(env, fmt.Sprintf("SCORSH_NEWREV=%s", msg.NewRev)) + env = append(env, fmt.Sprintf("SCORSH_ID=%s", msg.ID)) + env = append(env, fmt.Sprintf("SCORSH_COMMIT=%s", commitID)) + env = append(env, fmt.Sprintf("SCORSH_COMMAND=%s", cmd.Name)) + env = append(env, fmt.Sprintf("SCORSH_AUTHOR=%s", author)) + env = append(env, fmt.Sprintf("SCORSH_COMMITTER=%s", committer)) + cmd.Env = env +} + +func (cmd *command) String() string { + + var buff bytes.Buffer + + fmt.Fprintf(&buff, "Name: %s\n", cmd.Name) + fmt.Fprintf(&buff, "Keyrings: %s\n", cmd.Keyrings) + fmt.Fprintf(&buff, "Actions: %s\n", cmd.Actions) + fmt.Fprintf(&buff, "Env: %s\n", cmd.Env) + fmt.Fprintf(&buff, "Args: %s\n", cmd.Args) + return buff.String() +} -- cgit v1.2.3