-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Avoid duplicate email notification on workflow rerun #35575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
56dab26
to
5486690
Compare
@ChristopherHX I took a simpler approach by checking if the workflow has just been rerun in |
@badhezi I prefer the following instead of working around bugs of different places diff --git a/routers/web/repo/actions/view.go b/routers/web/repo/actions/view.go
index 232c627709..093ff56228 100644
--- a/routers/web/repo/actions/view.go
+++ b/routers/web/repo/actions/view.go
@@ -432,6 +432,7 @@ func Rerun(ctx *context_module.Context) {
run.PreviousDuration = run.Duration()
run.Started = 0
run.Stopped = 0
+ run.Status = actions_model.StatusWaiting
vars, err := actions_model.GetVariablesOfRun(ctx, run)
if err != nil {
diff --git a/tests/integration/repo_webhook_test.go b/tests/integration/repo_webhook_test.go
index d54a604655..49f6853abc 100644
--- a/tests/integration/repo_webhook_test.go
+++ b/tests/integration/repo_webhook_test.go
@@ -1418,7 +1418,7 @@ jobs:
assert.Equal(t, "user2/repo1", webhookData.payloads[1].Repo.FullName)
// Call rerun ui api
- // Only a web UI API exists for cancelling workflow runs, so use the UI endpoint.
+ // Only a web UI API exists for rerunning workflow runs, so use the UI endpoint.
rerunURL := fmt.Sprintf("/user2/repo1/actions/runs/%d/rerun", webhookData.payloads[0].WorkflowRun.RunNumber)
req = NewRequestWithValues(t, "POST", rerunURL, map[string]string{
"_csrf": GetUserCSRFToken(t, session),
@@ -1426,6 +1426,15 @@ jobs:
session.MakeRequest(t, req, http.StatusOK)
assert.Len(t, webhookData.payloads, 3)
+
+ // 5. Validate the third webhook payload
+ assert.Equal(t, "workflow_run", webhookData.triggeredEvent)
+ assert.Equal(t, "requested", webhookData.payloads[2].Action)
+ assert.Equal(t, "queued", webhookData.payloads[2].WorkflowRun.Status)
+ assert.Equal(t, repo1.DefaultBranch, webhookData.payloads[2].WorkflowRun.HeadBranch)
+ assert.Equal(t, commitID, webhookData.payloads[2].WorkflowRun.HeadSha)
+ assert.Equal(t, "repo1", webhookData.payloads[2].Repo.Name)
+ assert.Equal(t, "user2/repo1", webhookData.payloads[2].Repo.FullName)
}
func testWorkflowRunEventsOnCancellingAbandonedRun(t *testing.T, webhookData *workflowRunWebhook, allJobsAbandoned bool) { This ensure the status is not done for the event, so no email should be sent without additional changes. The workflow_run event is more than just email notification. |
Let me know if this works for you, I could also push into your pr with your explicit consent. |
Attempt to address #35556
When triggering a job re-run, we send a duplicate email notification in case the previous state of the job (prior to the re-run), required an email notification.
This change just sets the job status to
waiting
before all the notifiers evaluation so it will only notify at the end of the job run with the updated status.