Skip to content

Commit bf3559f

Browse files
committed
MAILER
1 parent bf468fe commit bf3559f

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

services/mailer/mail_workflow_run.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package mailer
55

66
import (
77
"bytes"
8-
api "code.gitea.io/gitea/modules/structs"
9-
"code.gitea.io/gitea/services/convert"
108
"context"
119
"fmt"
1210
"sort"
1311

12+
"code.gitea.io/gitea/services/convert"
13+
1414
"code.gitea.io/gitea/modules/translation"
1515

1616
actions_model "code.gitea.io/gitea/models/actions"
@@ -25,6 +25,13 @@ import (
2525

2626
const tplWorkflowRun = "notify/workflow_run"
2727

28+
type convertedWorkflowJob struct {
29+
HTMLURL string
30+
Status actions_model.Status
31+
Name string
32+
Attempt int64
33+
}
34+
2835
func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Repository, run *actions_model.ActionRun) string {
2936
return fmt.Sprintf("<%s/actions/runs/%d@%s>", repo.FullName(), run.Index, setting.Domain)
3037
}
@@ -34,16 +41,13 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
3441
headers := generateMetadataHeaders(repo)
3542

3643
subject := "Run"
37-
if run.IsForkPullRequest {
38-
subject = "PR run"
39-
}
4044
switch run.Status {
4145
case actions_model.StatusFailure:
42-
subject = subject + " failed"
46+
subject += " failed"
4347
case actions_model.StatusCancelled:
44-
subject = subject + " cancelled"
48+
subject += " cancelled"
4549
case actions_model.StatusSuccess:
46-
subject = subject + " is successful"
50+
subject += " is successful"
4751
}
4852
subject = fmt.Sprintf("%s: %s (%s)", subject, run.WorkflowID, base.ShortSha(run.CommitSHA))
4953

@@ -63,14 +67,19 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
6367
return si < sj
6468
})
6569
}
66-
convertedJobs0 := make([]*api.ActionWorkflowJob, 0, len(jobs0))
70+
convertedJobs := make([]convertedWorkflowJob, 0, len(jobs0))
6771
for _, job := range jobs0 {
6872
c, err := convert.ToActionWorkflowJob(ctx, repo, nil, job)
6973
if err != nil {
7074
log.Error("convert.ToActionWorkflowJob: %v", err)
7175
continue
7276
}
73-
convertedJobs0 = append(convertedJobs0, c)
77+
convertedJobs = append(convertedJobs, convertedWorkflowJob{
78+
HTMLURL: c.HTMLURL,
79+
Name: c.Name,
80+
Status: job.Status,
81+
Attempt: c.RunAttempt,
82+
})
7483
}
7584

7685
displayName := fromDisplayName(sender)
@@ -96,7 +105,7 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
96105
"Repo": repo,
97106
"Run": run,
98107
"RunStatusText": runStatusText,
99-
"Jobs": convertedJobs0,
108+
"Jobs": convertedJobs,
100109
"locale": locale,
101110
"Language": locale.Language(),
102111
}); err != nil {

templates/mail/notify/workflow_run.tmpl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
55
<meta name="format-detection" content="telephone=no,date=no,address=no,email=no,url=no">
66
<title>{{.Subject}}</title>
7-
<style>
8-
.footer { font-size: small; color: #666; }
9-
</style>
107
</head>
118
<body>
129
<h4>
@@ -16,17 +13,14 @@
1613
{{range $job := .Jobs}}
1714
<li>
1815
<a href="{{$job.HTMLURL}}">
19-
{{$job.Status}}: {{$job.Name}}{{if gt $job.RunAttempt 1}}, Attempt #{{$job.RunAttempt}}{{end}}
16+
{{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}
2017
</a>
2118
</li>
2219
{{end}}
2320
</ul>
24-
<div class="footer">
2521
<p>
26-
---
2722
<br>
2823
<a href="{{.Run.HTMLURL}}">{{.locale.Tr "mail.view_it_on" AppName}}</a>.
2924
</p>
30-
</div>
3125
</body>
3226
</html>

0 commit comments

Comments
 (0)