Skip to content

Conversation

badhezi
Copy link
Contributor

@badhezi badhezi commented Oct 3, 2025

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.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Oct 3, 2025
@github-actions github-actions bot added the modifies/go Pull requests that update Go code label Oct 3, 2025
@badhezi badhezi changed the title Hezi/update run status on rerun Update job status on rerun - avoid duplicate email notification Oct 3, 2025
@badhezi badhezi marked this pull request as draft October 3, 2025 17:19
@badhezi badhezi force-pushed the hezi/update-run-status-on-rerun branch from 56dab26 to 5486690 Compare October 8, 2025 08:40
@badhezi badhezi marked this pull request as ready for review October 8, 2025 08:43
@badhezi
Copy link
Contributor Author

badhezi commented Oct 8, 2025

@ChristopherHX I took a simpler approach by checking if the workflow has just been rerun in MailActionsTrigger and skip just the email composition part in that case, this should leave existing notifiers as-is and just skip the email send on reruns. Hopes this address the issue without any unwanted behavior change.

@badhezi badhezi requested a review from ChristopherHX October 8, 2025 17:01
@badhezi badhezi changed the title Update job status on rerun - avoid duplicate email notification Avoid duplicate email notification on workflow rerun Oct 8, 2025
@ChristopherHX
Copy link
Contributor

@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.

@ChristopherHX
Copy link
Contributor

Let me know if this works for you, I could also push into your pr with your explicit consent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/go Pull requests that update Go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants