diff options
Diffstat (limited to 'types.go')
-rw-r--r-- | types.go | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -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() +} |