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:
@@ -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)
|
ctx, cancel := context.WithTimeout(r.ctx, 30*time.Second)
|
||||||
defer cancel()
|
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)
|
summary = truncateUTF8(summary, 1800)
|
||||||
title := fmt.Sprintf("Pipeline stage %s", event)
|
title := fmt.Sprintf("Pipeline stage %s", event)
|
||||||
receipts := []protocol.NotificationReceipt{}
|
receipts := []protocol.NotificationReceipt{}
|
||||||
@@ -520,3 +520,17 @@ func notificationArtifact(workspace, name string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
return data, nil
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user