diff --git a/internal/server/notify.go b/internal/server/notify.go index 1306cb6e..891455d1 100644 --- a/internal/server/notify.go +++ b/internal/server/notify.go @@ -54,7 +54,7 @@ func (r *runner) notifyStep(id int64, name, workspace string, policy *protocol.N } ctx, cancel := context.WithTimeout(r.ctx, 30*time.Second) defer cancel() - summary := fmt.Sprintf("%s · run #%d · stage %s · %s (%s)", name, id, step.Stage, event, step.Outcome) + summary := stageNotificationSummary(name, id, step.Stage, event, step.Outcome) summary = truncateUTF8(summary, 1800) title := fmt.Sprintf("Pipeline stage %s", event) receipts := []protocol.NotificationReceipt{} @@ -520,3 +520,17 @@ func notificationArtifact(workspace, name string) ([]byte, error) { } return data, nil } + +// stageNotificationSummary is a stage notification's one-line body. The +// outcome is shown only when the stage recorded one (a waiting human stage has +// none yet), and a waiting stage says what it waits for. +func stageNotificationSummary(name string, runID int64, stage, event, outcome string) string { + state := event + if event == "waiting" { + state = "waiting for your decision" + } + if outcome = strings.TrimSpace(outcome); outcome != "" { + state += " (" + outcome + ")" + } + return fmt.Sprintf("%s · run #%d · stage %s · %s", name, runID, stage, state) +} diff --git a/internal/server/notify_summary_test.go b/internal/server/notify_summary_test.go new file mode 100644 index 00000000..b832beeb --- /dev/null +++ b/internal/server/notify_summary_test.go @@ -0,0 +1,16 @@ +package server + +import "testing" + +func TestStageNotificationSummaryOmitsEmptyOutcome(t *testing.T) { + cases := []struct{ event, outcome, want string }{ + {"waiting", "", "Demo · run #229 · stage Feedback · waiting for your decision"}, + {"failed", "error", "Demo · run #229 · stage Feedback · failed (error)"}, + {"succeeded", " ", "Demo · run #229 · stage Feedback · succeeded"}, + } + for _, c := range cases { + if got := stageNotificationSummary("Demo", 229, "Feedback", c.event, c.outcome); got != c.want { + t.Errorf("%s/%q: got %q, want %q", c.event, c.outcome, got, c.want) + } + } +}