8
8
"context"
9
9
"fmt"
10
10
"sort"
11
+ "time"
11
12
12
13
actions_model "code.gitea.io/gitea/models/actions"
13
14
repo_model "code.gitea.io/gitea/models/repo"
@@ -24,27 +25,27 @@ import (
24
25
const tplWorkflowRun templates.TplName = "repo/actions/workflow_run"
25
26
26
27
type 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
31
33
}
32
34
33
35
func generateMessageIDForActionsWorkflowRunStatusEmail (repo * repo_model.Repository , run * actions_model.ActionRun ) string {
34
36
return fmt .Sprintf ("<%s/actions/runs/%d@%s>" , repo .FullName (), run .Index , setting .Domain )
35
37
}
36
38
37
39
func 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
39
41
switch run .Status {
40
42
case actions_model .StatusFailure :
41
- subject + = " failed"
43
+ subjectTrString = "mail.repo.actions.run. failed"
42
44
case actions_model .StatusCancelled :
43
- subject + = " cancelled"
45
+ subjectTrString = "mail.repo.actions.run. cancelled"
44
46
case actions_model .StatusSuccess :
45
- subject + = " succeeded"
47
+ subjectTrString = "mail.repo.actions.run. succeeded"
46
48
}
47
- subject = fmt .Sprintf ("%s: %s (%s)" , subject , run .WorkflowID , base .ShortSha (run .CommitSHA ))
48
49
displayName := fromDisplayName (sender )
49
50
messageID := generateMessageIDForActionsWorkflowRunStatusEmail (repo , run )
50
51
metadataHeaders := generateMetadataHeaders (repo )
@@ -75,10 +76,11 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
75
76
continue
76
77
}
77
78
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 (),
82
84
})
83
85
}
84
86
@@ -88,27 +90,28 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
88
90
}
89
91
for lang , tos := range langMap {
90
92
locale := translation .NewLocale (lang )
91
- var runStatusText string
93
+ var runStatusTrString string
92
94
switch run .Status {
93
95
case actions_model .StatusSuccess :
94
- runStatusText = "All jobs have succeeded "
96
+ runStatusTrString = "mail.repo.actions. jobs.all_succeeded "
95
97
case actions_model .StatusFailure :
96
- runStatusText = "All jobs have failed "
98
+ runStatusTrString = "mail.repo.actions. jobs.all_failed "
97
99
for _ , job := range jobs {
98
100
if ! job .Status .IsFailure () {
99
- runStatusText = "Some jobs were not successful "
101
+ runStatusTrString = "mail.repo.actions. jobs.some_not_successful "
100
102
break
101
103
}
102
104
}
103
105
case actions_model .StatusCancelled :
104
- runStatusText = "All jobs have been cancelled "
106
+ runStatusTrString = "mail.repo.actions. jobs.all_cancelled "
105
107
}
108
+ subject := fmt .Sprintf ("%s: %s (%s)" , locale .TrString (subjectTrString ), run .WorkflowID , base .ShortSha (run .CommitSHA ))
106
109
var mailBody bytes.Buffer
107
110
if err := LoadedTemplates ().BodyTemplates .ExecuteTemplate (& mailBody , string (tplWorkflowRun ), map [string ]any {
108
111
"Subject" : subject ,
109
112
"Repo" : repo ,
110
113
"Run" : run ,
111
- "RunStatusText" : runStatusText ,
114
+ "RunStatusText" : locale . TrString ( runStatusTrString ) ,
112
115
"Jobs" : convertedJobs ,
113
116
"locale" : locale ,
114
117
}); err != nil {
0 commit comments