Stage notifications: no empty "()" and say what a waiting stage needs

A waiting human stage has no outcome yet, so its notification read
"… · waiting ()". The outcome is now shown only when recorded, and a
waiting stage reads "waiting for your decision".
This commit is contained in:
2026-11-02 15:47:06 +00:00
parent 1c8680393e
commit 815f7c2a5a
2 changed files with 31 additions and 1 deletions
+15 -1
View File
@@ -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)
}
+16
View File
@@ -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)
}
}
}