88 "context"
99 "fmt"
1010 "sort"
11+ "time"
1112
1213 actions_model "code.gitea.io/gitea/models/actions"
1314 repo_model "code.gitea.io/gitea/models/repo"
@@ -24,27 +25,27 @@ import (
2425const tplWorkflowRun templates.TplName = "repo/actions/workflow_run"
2526
2627type convertedWorkflowJob struct {
27- HTMLURL string
28- Status actions_model.Status
29- Name string
30- Attempt int64
28+ HTMLURL string
29+ Name string
30+ Status actions_model.Status
31+ Attempt int64
32+ Duration time.Duration
3133}
3234
3335func generateMessageIDForActionsWorkflowRunStatusEmail (repo * repo_model.Repository , run * actions_model.ActionRun ) string {
3436 return fmt .Sprintf ("<%s/actions/runs/%d@%s>" , repo .FullName (), run .Index , setting .Domain )
3537}
3638
3739func composeAndSendActionsWorkflowRunStatusEmail (ctx context.Context , repo * repo_model.Repository , run * actions_model.ActionRun , sender * user_model.User , recipients []* user_model.User ) {
38- subject := "Run"
40+ var subjectTrString string
3941 switch run .Status {
4042 case actions_model .StatusFailure :
41- subject + = " failed"
43+ subjectTrString = "mail.repo.actions.run. failed"
4244 case actions_model .StatusCancelled :
43- subject + = " cancelled"
45+ subjectTrString = "mail.repo.actions.run. cancelled"
4446 case actions_model .StatusSuccess :
45- subject + = " succeeded"
47+ subjectTrString = "mail.repo.actions.run. succeeded"
4648 }
47- subject = fmt .Sprintf ("%s: %s (%s)" , subject , run .WorkflowID , base .ShortSha (run .CommitSHA ))
4849 displayName := fromDisplayName (sender )
4950 messageID := generateMessageIDForActionsWorkflowRunStatusEmail (repo , run )
5051 metadataHeaders := generateMetadataHeaders (repo )
@@ -75,10 +76,11 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
7576 continue
7677 }
7778 convertedJobs = append (convertedJobs , convertedWorkflowJob {
78- HTMLURL : converted0 .HTMLURL ,
79- Name : converted0 .Name ,
80- Status : job .Status ,
81- Attempt : converted0 .RunAttempt ,
79+ HTMLURL : converted0 .HTMLURL ,
80+ Name : converted0 .Name ,
81+ Status : job .Status ,
82+ Attempt : converted0 .RunAttempt ,
83+ Duration : job .Duration (),
8284 })
8385 }
8486
@@ -88,27 +90,28 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
8890 }
8991 for lang , tos := range langMap {
9092 locale := translation .NewLocale (lang )
91- var runStatusText string
93+ var runStatusTrString string
9294 switch run .Status {
9395 case actions_model .StatusSuccess :
94- runStatusText = "All jobs have succeeded "
96+ runStatusTrString = "mail.repo.actions. jobs.all_succeeded "
9597 case actions_model .StatusFailure :
96- runStatusText = "All jobs have failed "
98+ runStatusTrString = "mail.repo.actions. jobs.all_failed "
9799 for _ , job := range jobs {
98100 if ! job .Status .IsFailure () {
99- runStatusText = "Some jobs were not successful "
101+ runStatusTrString = "mail.repo.actions. jobs.some_not_successful "
100102 break
101103 }
102104 }
103105 case actions_model .StatusCancelled :
104- runStatusText = "All jobs have been cancelled "
106+ runStatusTrString = "mail.repo.actions. jobs.all_cancelled "
105107 }
108+ subject := fmt .Sprintf ("%s: %s (%s)" , locale .TrString (subjectTrString ), run .WorkflowID , base .ShortSha (run .CommitSHA ))
106109 var mailBody bytes.Buffer
107110 if err := LoadedTemplates ().BodyTemplates .ExecuteTemplate (& mailBody , string (tplWorkflowRun ), map [string ]any {
108111 "Subject" : subject ,
109112 "Repo" : repo ,
110113 "Run" : run ,
111- "RunStatusText" : runStatusText ,
114+ "RunStatusText" : locale . TrString ( runStatusTrString ) ,
112115 "Jobs" : convertedJobs ,
113116 "locale" : locale ,
114117 }); err != nil {
0 commit comments