Notify on failed runs and with ntfy disabled
This commit is contained in:
@@ -78,9 +78,8 @@ func TestNotificationSettingsRejectUnknownOrInvalid(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// A run's end (succeeded or failed) enqueues its generic alert only for a run
|
||||
// marked "on", or for "auto" when run_finished (default off) opts into every
|
||||
// run end. Waiting notifies auto and on runs regardless; "off" never notifies.
|
||||
// Failed runs always enqueue their generic alert (unless off). Successful runs
|
||||
// require "on" or run_finished. Waiting notifies auto and on runs regardless.
|
||||
func TestRunEndEnqueueFollowsNotifyModeAndRunFinished(t *testing.T) {
|
||||
for _, status := range []string{"succeeded", "failed", "waiting"} {
|
||||
for _, tc := range []struct {
|
||||
@@ -91,6 +90,9 @@ func TestRunEndEnqueueFollowsNotifyModeAndRunFinished(t *testing.T) {
|
||||
{"auto", false, 0}, {"auto", true, 1}, {"on", false, 1}, {"on", true, 1}, {"off", false, 0}, {"off", true, 0},
|
||||
} {
|
||||
want := tc.want
|
||||
if status == "failed" && tc.mode == "auto" {
|
||||
want = 1
|
||||
}
|
||||
if status == "waiting" && tc.mode == "auto" {
|
||||
want = 1
|
||||
}
|
||||
@@ -138,7 +140,7 @@ func TestLegacyRunFinishedValueIsIgnored(t *testing.T) {
|
||||
if err := notificationTransition(ctx, s, id, "failed"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, err := s.RunNotifications(ctx, id); err != nil || len(got) != 0 {
|
||||
if got, err := s.RunNotifications(ctx, id); err != nil || len(got) != 1 {
|
||||
t.Fatalf("notifications = %+v, %v", got, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,10 +144,10 @@ func TestRunNotificationTransitionModesAndCoverage(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// run_finished defaults off, so an auto run notifies only
|
||||
// while waiting; its end is silent unless marked "on".
|
||||
// Failed runs always notify in auto mode; successful runs require
|
||||
// "on" or run_finished. Waiting notifies auto and on.
|
||||
want := 1
|
||||
if mode == "off" || (mode == "auto" && status != "waiting") {
|
||||
if mode == "off" || (mode == "auto" && status == "succeeded") {
|
||||
want = 0
|
||||
}
|
||||
if len(ns) != want {
|
||||
|
||||
@@ -42,10 +42,10 @@ JOIN pipeline_versions v ON v.pipeline_id=r.pipeline_id AND v.version=r.version
|
||||
case "waiting":
|
||||
title = "Run needs your decision"
|
||||
body = "waiting for a human decision"
|
||||
case "failed", "succeeded":
|
||||
// A run's end notifies only for runs marked "on", unless the operator
|
||||
case "failed", "interrupted", "succeeded":
|
||||
// Successful runs notify only for runs marked "on", unless the operator
|
||||
// opted into every run end via run_finished, read in this transaction.
|
||||
if mode != "on" {
|
||||
if status == "succeeded" && mode != "on" {
|
||||
settings, err := readNotificationSettings(ctx, tx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user