From 5c6c94e6a729a4cf71f51921e3e597b99f0e2dae Mon Sep 17 00:00:00 2001 From: NorthRealm <155140859+NorthRealm@users.noreply.github.com> Date: Thu, 24 Jul 2025 01:14:42 +0800 Subject: [PATCH] UPDATE --- options/locale/locale_en-US.ini | 8 ++++ services/mailer/mail_workflow_run.go | 41 ++++++++++--------- .../repo/actions/workflow_run.devtest.yml | 2 + templates/mail/repo/actions/workflow_run.tmpl | 2 +- 4 files changed, 33 insertions(+), 20 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c1a3d37037f..ff331b97714 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -550,6 +550,14 @@ repo.transfer.body = To accept or reject it visit %s or just ignore it. repo.collaborator.added.subject = %s added you to %s repo.collaborator.added.text = You have been added as a collaborator of repository: +repo.actions.run.failed = Run failed +repo.actions.run.succeeded = Run succeeded +repo.actions.run.cancelled = Run cancelled +repo.actions.jobs.all_succeeded = All jobs have succeeded +repo.actions.jobs.all_failed = All jobs have failed +repo.actions.jobs.some_not_successful = Some jobs were not successful +repo.actions.jobs.all_cancelled = All jobs have been cancelled + team_invite.subject = %[1]s has invited you to join the %[2]s organization team_invite.text_1 = %[1]s has invited you to join team %[2]s in organization %[3]s. team_invite.text_2 = Please click the following link to join the team: diff --git a/services/mailer/mail_workflow_run.go b/services/mailer/mail_workflow_run.go index da791894a53..664d1bd1654 100644 --- a/services/mailer/mail_workflow_run.go +++ b/services/mailer/mail_workflow_run.go @@ -8,6 +8,7 @@ import ( "context" "fmt" "sort" + "time" actions_model "code.gitea.io/gitea/models/actions" repo_model "code.gitea.io/gitea/models/repo" @@ -24,10 +25,11 @@ import ( const tplWorkflowRun templates.TplName = "repo/actions/workflow_run" type convertedWorkflowJob struct { - HTMLURL string - Status actions_model.Status - Name string - Attempt int64 + HTMLURL string + Name string + Status actions_model.Status + Attempt int64 + Duration time.Duration } func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Repository, run *actions_model.ActionRun) string { @@ -35,16 +37,15 @@ func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Reposito } func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun, sender *user_model.User, recipients []*user_model.User) { - subject := "Run" + var subjectTrString string switch run.Status { case actions_model.StatusFailure: - subject += " failed" + subjectTrString = "mail.repo.actions.run.failed" case actions_model.StatusCancelled: - subject += " cancelled" + subjectTrString = "mail.repo.actions.run.cancelled" case actions_model.StatusSuccess: - subject += " succeeded" + subjectTrString = "mail.repo.actions.run.succeeded" } - subject = fmt.Sprintf("%s: %s (%s)", subject, run.WorkflowID, base.ShortSha(run.CommitSHA)) displayName := fromDisplayName(sender) messageID := generateMessageIDForActionsWorkflowRunStatusEmail(repo, run) metadataHeaders := generateMetadataHeaders(repo) @@ -75,10 +76,11 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo continue } convertedJobs = append(convertedJobs, convertedWorkflowJob{ - HTMLURL: converted0.HTMLURL, - Name: converted0.Name, - Status: job.Status, - Attempt: converted0.RunAttempt, + HTMLURL: converted0.HTMLURL, + Name: converted0.Name, + Status: job.Status, + Attempt: converted0.RunAttempt, + Duration: job.Duration(), }) } @@ -88,27 +90,28 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo } for lang, tos := range langMap { locale := translation.NewLocale(lang) - var runStatusText string + var runStatusTrString string switch run.Status { case actions_model.StatusSuccess: - runStatusText = "All jobs have succeeded" + runStatusTrString = "mail.repo.actions.jobs.all_succeeded" case actions_model.StatusFailure: - runStatusText = "All jobs have failed" + runStatusTrString = "mail.repo.actions.jobs.all_failed" for _, job := range jobs { if !job.Status.IsFailure() { - runStatusText = "Some jobs were not successful" + runStatusTrString = "mail.repo.actions.jobs.some_not_successful" break } } case actions_model.StatusCancelled: - runStatusText = "All jobs have been cancelled" + runStatusTrString = "mail.repo.actions.jobs.all_cancelled" } + subject := fmt.Sprintf("%s: %s (%s)", locale.TrString(subjectTrString), run.WorkflowID, base.ShortSha(run.CommitSHA)) var mailBody bytes.Buffer if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&mailBody, string(tplWorkflowRun), map[string]any{ "Subject": subject, "Repo": repo, "Run": run, - "RunStatusText": runStatusText, + "RunStatusText": locale.TrString(runStatusTrString), "Jobs": convertedJobs, "locale": locale, }); err != nil { diff --git a/templates/mail/repo/actions/workflow_run.devtest.yml b/templates/mail/repo/actions/workflow_run.devtest.yml index 3d93ad45a3a..a45b26a6eef 100644 --- a/templates/mail/repo/actions/workflow_run.devtest.yml +++ b/templates/mail/repo/actions/workflow_run.devtest.yml @@ -12,7 +12,9 @@ Jobs: Status: success Attempt: 1 HTMLURL: http://localhost/job/1 + Duration: 1h2m3s - Name: Job-Name-2 Status: failure Attempt: 2 HTMLURL: http://localhost/job/2 + Duration: 1h2m3s diff --git a/templates/mail/repo/actions/workflow_run.tmpl b/templates/mail/repo/actions/workflow_run.tmpl index f6dd8ad510e..619ee6fa20f 100644 --- a/templates/mail/repo/actions/workflow_run.tmpl +++ b/templates/mail/repo/actions/workflow_run.tmpl @@ -15,7 +15,7 @@ {{range $job := .Jobs}}
  • - {{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}} + {{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}, {{$job.Duration}}
  • {{end}}