mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-21 16:45:03 +02:00
MAILER
This commit is contained in:
parent
bf468fee21
commit
bf3559f0b5
@ -5,12 +5,12 @@ package mailer
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
"context"
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"code.gitea.io/gitea/services/convert"
|
||||
|
||||
"code.gitea.io/gitea/modules/translation"
|
||||
|
||||
actions_model "code.gitea.io/gitea/models/actions"
|
||||
@ -25,6 +25,13 @@ import (
|
||||
|
||||
const tplWorkflowRun = "notify/workflow_run"
|
||||
|
||||
type convertedWorkflowJob struct {
|
||||
HTMLURL string
|
||||
Status actions_model.Status
|
||||
Name string
|
||||
Attempt int64
|
||||
}
|
||||
|
||||
func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Repository, run *actions_model.ActionRun) string {
|
||||
return fmt.Sprintf("<%s/actions/runs/%d@%s>", repo.FullName(), run.Index, setting.Domain)
|
||||
}
|
||||
@ -34,16 +41,13 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
|
||||
headers := generateMetadataHeaders(repo)
|
||||
|
||||
subject := "Run"
|
||||
if run.IsForkPullRequest {
|
||||
subject = "PR run"
|
||||
}
|
||||
switch run.Status {
|
||||
case actions_model.StatusFailure:
|
||||
subject = subject + " failed"
|
||||
subject += " failed"
|
||||
case actions_model.StatusCancelled:
|
||||
subject = subject + " cancelled"
|
||||
subject += " cancelled"
|
||||
case actions_model.StatusSuccess:
|
||||
subject = subject + " is successful"
|
||||
subject += " is successful"
|
||||
}
|
||||
subject = fmt.Sprintf("%s: %s (%s)", subject, run.WorkflowID, base.ShortSha(run.CommitSHA))
|
||||
|
||||
@ -63,14 +67,19 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
|
||||
return si < sj
|
||||
})
|
||||
}
|
||||
convertedJobs0 := make([]*api.ActionWorkflowJob, 0, len(jobs0))
|
||||
convertedJobs := make([]convertedWorkflowJob, 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)
|
||||
convertedJobs = append(convertedJobs, convertedWorkflowJob{
|
||||
HTMLURL: c.HTMLURL,
|
||||
Name: c.Name,
|
||||
Status: job.Status,
|
||||
Attempt: c.RunAttempt,
|
||||
})
|
||||
}
|
||||
|
||||
displayName := fromDisplayName(sender)
|
||||
@ -96,7 +105,7 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
|
||||
"Repo": repo,
|
||||
"Run": run,
|
||||
"RunStatusText": runStatusText,
|
||||
"Jobs": convertedJobs0,
|
||||
"Jobs": convertedJobs,
|
||||
"locale": locale,
|
||||
"Language": locale.Language(),
|
||||
}); err != nil {
|
||||
|
@ -4,9 +4,6 @@
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<meta name="format-detection" content="telephone=no,date=no,address=no,email=no,url=no">
|
||||
<title>{{.Subject}}</title>
|
||||
<style>
|
||||
.footer { font-size: small; color: #666; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h4>
|
||||
@ -16,17 +13,14 @@
|
||||
{{range $job := .Jobs}}
|
||||
<li>
|
||||
<a href="{{$job.HTMLURL}}">
|
||||
{{$job.Status}}: {{$job.Name}}{{if gt $job.RunAttempt 1}}, Attempt #{{$job.RunAttempt}}{{end}}
|
||||
{{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}
|
||||
</a>
|
||||
</li>
|
||||
{{end}}
|
||||
</ul>
|
||||
<div class="footer">
|
||||
<p>
|
||||
---
|
||||
<br>
|
||||
<a href="{{.Run.HTMLURL}}">{{.locale.Tr "mail.view_it_on" AppName}}</a>.
|
||||
</p>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
Loading…
x
Reference in New Issue
Block a user