Skip to content

Commit 5c6c94e

Browse files
committed
UPDATE
1 parent d890db1 commit 5c6c94e

File tree

4 files changed

+33
-20
lines changed

4 files changed

+33
-20
lines changed

options/locale/locale_en-US.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,14 @@ repo.transfer.body = To accept or reject it visit %s or just ignore it.
550550
repo.collaborator.added.subject = %s added you to %s
551551
repo.collaborator.added.text = You have been added as a collaborator of repository:
552552
553+
repo.actions.run.failed = Run failed
554+
repo.actions.run.succeeded = Run succeeded
555+
repo.actions.run.cancelled = Run cancelled
556+
repo.actions.jobs.all_succeeded = All jobs have succeeded
557+
repo.actions.jobs.all_failed = All jobs have failed
558+
repo.actions.jobs.some_not_successful = Some jobs were not successful
559+
repo.actions.jobs.all_cancelled = All jobs have been cancelled
560+
553561
team_invite.subject = %[1]s has invited you to join the %[2]s organization
554562
team_invite.text_1 = %[1]s has invited you to join team %[2]s in organization %[3]s.
555563
team_invite.text_2 = Please click the following link to join the team:

services/mailer/mail_workflow_run.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
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 (
2425
const tplWorkflowRun templates.TplName = "repo/actions/workflow_run"
2526

2627
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
3133
}
3234

3335
func 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

3739
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
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 {

templates/mail/repo/actions/workflow_run.devtest.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ Jobs:
1212
Status: success
1313
Attempt: 1
1414
HTMLURL: http://localhost/job/1
15+
Duration: 1h2m3s
1516
- Name: Job-Name-2
1617
Status: failure
1718
Attempt: 2
1819
HTMLURL: http://localhost/job/2
20+
Duration: 1h2m3s

templates/mail/repo/actions/workflow_run.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
{{range $job := .Jobs}}
1616
<li style="background-color: #ffffff; border: 1px solid #ddd; border-radius: 6px; padding: 12px 16px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); transition: box-shadow 0.2s ease;">
1717
<a href="{{$job.HTMLURL}}" style="color: #0073e6; text-decoration: none; font-weight: bold;">
18-
{{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}
18+
{{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}, {{$job.Duration}}
1919
</a>
2020
</li>
2121
{{end}}

0 commit comments

Comments
 (0)