mirror of
https://github.com/OliveTin/OliveTin
synced 2025-12-12 00:55:34 +00:00
Notification support (#183)
* feature: #158 shellAfterComplete support for notifications * fmt: reduce cyclo
This commit is contained in:
@@ -83,6 +83,7 @@ func DefaultExecutor() *Executor {
|
||||
stepParseArgs,
|
||||
stepLogStart,
|
||||
stepExec,
|
||||
stepExecAfter,
|
||||
stepLogFinish,
|
||||
}
|
||||
|
||||
@@ -300,3 +301,47 @@ func stepExec(req *ExecutionRequest) bool {
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func stepExecAfter(req *ExecutionRequest) bool {
|
||||
if req.action.ShellAfterCompleted == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(req.action.Timeout)*time.Second)
|
||||
defer cancel()
|
||||
|
||||
var stdout bytes.Buffer
|
||||
var stderr bytes.Buffer
|
||||
|
||||
args := map[string]string{
|
||||
"stdout": req.logEntry.Stdout,
|
||||
"exitCode": fmt.Sprintf("%v", req.logEntry.ExitCode),
|
||||
}
|
||||
|
||||
finalParsedCommand, _ := parseActionArguments(req.action.ShellAfterCompleted, args, req.action)
|
||||
|
||||
cmd := wrapCommandInShell(ctx, finalParsedCommand)
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
req.logEntry.StdoutBuffer, _ = cmd.StdoutPipe()
|
||||
req.logEntry.StderrBuffer, _ = cmd.StderrPipe()
|
||||
|
||||
runerr := cmd.Start()
|
||||
|
||||
cmd.Wait()
|
||||
|
||||
req.logEntry.Stdout += "---\n" + stdout.String()
|
||||
req.logEntry.Stderr += "---\n" + stderr.String()
|
||||
|
||||
if runerr != nil {
|
||||
req.logEntry.Stderr = runerr.Error() + "\n\n" + req.logEntry.Stderr
|
||||
}
|
||||
|
||||
if ctx.Err() == context.DeadlineExceeded {
|
||||
req.logEntry.Stderr += "Your shellAfterCommand command timed out."
|
||||
}
|
||||
|
||||
req.logEntry.Stdout += fmt.Sprintf("Your shellAfterCommand exited with code %v", cmd.ProcessState.ExitCode())
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user