mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 12:24:38 +02:00
MAILER
This commit is contained in:
parent
1f6c68d572
commit
bf468fee21
@ -5,6 +5,8 @@ package mailer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
@ -45,13 +47,13 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
|
||||
}
|
||||
subject = fmt.Sprintf("%s: %s (%s)", subject, run.WorkflowID, base.ShortSha(run.CommitSHA))
|
||||
|
||||
jobs, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
|
||||
jobs0, err := actions_model.GetRunJobsByRunID(ctx, run.ID)
|
||||
if err != nil {
|
||||
log.Error("GetRunJobsByRunID: %v", err)
|
||||
} else {
|
||||
sort.SliceStable(jobs, func(i, j int) bool {
|
||||
si := jobs[i].Status
|
||||
sj := jobs[j].Status
|
||||
sort.SliceStable(jobs0, func(i, j int) bool {
|
||||
si := jobs0[i].Status
|
||||
sj := jobs0[j].Status
|
||||
if si.IsSuccess() {
|
||||
si = 99
|
||||
}
|
||||
@ -61,6 +63,15 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
|
||||
return si < sj
|
||||
})
|
||||
}
|
||||
convertedJobs0 := make([]*api.ActionWorkflowJob, 0, len(jobs0))
|
||||
for _, job := range jobs0 {
|
||||
c, err := convert.ToActionWorkflowJob(ctx, repo, nil, job)
|
||||
if err != nil {
|
||||
log.Error("convert.ToActionWorkflowJob: %v", err)
|
||||
continue
|
||||
}
|
||||
convertedJobs0 = append(convertedJobs0, c)
|
||||
}
|
||||
|
||||
displayName := fromDisplayName(sender)
|
||||
|
||||
@ -70,14 +81,24 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
|
||||
}
|
||||
for lang, tos := range langMap {
|
||||
locale := translation.NewLocale(lang)
|
||||
var runStatusText string
|
||||
switch run.Status {
|
||||
case actions_model.StatusSuccess:
|
||||
runStatusText = locale.TrString("actions.status.success")
|
||||
case actions_model.StatusFailure:
|
||||
runStatusText = locale.TrString("actions.status.failure")
|
||||
case actions_model.StatusCancelled:
|
||||
runStatusText = locale.TrString("actions.status.cancelled")
|
||||
}
|
||||
var mailBody bytes.Buffer
|
||||
if err := bodyTemplates.ExecuteTemplate(&mailBody, tplWorkflowRun, map[string]any{
|
||||
"Subject": subject,
|
||||
"Repo": repo,
|
||||
"Run": run,
|
||||
"Jobs": jobs,
|
||||
"locale": locale,
|
||||
"Language": locale.Language(),
|
||||
"Subject": subject,
|
||||
"Repo": repo,
|
||||
"Run": run,
|
||||
"RunStatusText": runStatusText,
|
||||
"Jobs": convertedJobs0,
|
||||
"locale": locale,
|
||||
"Language": locale.Language(),
|
||||
}); err != nil {
|
||||
log.Error("ExecuteTemplate [%s]: %v", tplWorkflowRun, err)
|
||||
}
|
||||
|
@ -10,12 +10,14 @@
|
||||
</head>
|
||||
<body>
|
||||
<h4>
|
||||
{{.Repo.FullName}} {{.Run.WorkflowID}}: {{if .Run.Status.IsSuccess}}{{.locale.Tr "actions.status.success"}}{{else if .Run.Status.IsFailure}}{{.locale.Tr "actions.status.failure"}}{{else if .Run.Status.IsCancelled}}{{.locale.Tr "actions.status.cancelled"}}{{else}}{{.locale.Tr "actions.status.skipped"}}{{end}}
|
||||
{{.Repo.FullName}} {{.Run.WorkflowID}}: {{.RunStatusText}}
|
||||
</h4>
|
||||
<ul>
|
||||
{{range $job := .Jobs}}
|
||||
<li>
|
||||
{{if $job.Status.IsSuccess}}{{.locale.Tr "actions.status.success"}}{{else if $job.Status.IsFailure}}{{.locale.Tr "actions.status.failure"}}{{else if $job.Status.IsCancelled}}{{.locale.Tr "actions.status.cancelled"}}{{else}}{{.locale.Tr "actions.status.skipped"}}{{end}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}
|
||||
<a href="{{$job.HTMLURL}}">
|
||||
{{$job.Status}}: {{$job.Name}}{{if gt $job.RunAttempt 1}}, Attempt #{{$job.RunAttempt}}{{end}}
|
||||
</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
|
Loading…
x
Reference in New Issue
Block a user