mirror of
https://github.com/go-gitea/gitea.git
synced 2025-11-05 03:56:10 +01:00
MAILER
This commit is contained in:
parent
a63093528a
commit
1f6c68d572
@ -9,6 +9,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/translation"
|
||||||
|
|
||||||
actions_model "code.gitea.io/gitea/models/actions"
|
actions_model "code.gitea.io/gitea/models/actions"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
repo_model "code.gitea.io/gitea/models/repo"
|
repo_model "code.gitea.io/gitea/models/repo"
|
||||||
@ -26,8 +28,6 @@ func generateMessageIDForActionsWorkflowRunStatusEmail(repo *repo_model.Reposito
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun, sender *user_model.User, recipients []*user_model.User) {
|
func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Repository, run *actions_model.ActionRun, sender *user_model.User, recipients []*user_model.User) {
|
||||||
msgs := make([]*sender_service.Message, 0, len(recipients))
|
|
||||||
|
|
||||||
messageID := generateMessageIDForActionsWorkflowRunStatusEmail(repo, run)
|
messageID := generateMessageIDForActionsWorkflowRunStatusEmail(repo, run)
|
||||||
headers := generateMetadataHeaders(repo)
|
headers := generateMetadataHeaders(repo)
|
||||||
|
|
||||||
@ -62,35 +62,46 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var mailBody bytes.Buffer
|
displayName := fromDisplayName(sender)
|
||||||
if err := bodyTemplates.ExecuteTemplate(&mailBody, tplWorkflowRun, map[string]any{
|
|
||||||
"Subject": subject,
|
|
||||||
"Repo": repo,
|
|
||||||
"Run": run,
|
|
||||||
"Jobs": jobs,
|
|
||||||
}); err != nil {
|
|
||||||
log.Error("ExecuteTemplate [%s]: %v", tplWorkflowRun, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, recipient := range recipients {
|
langMap := make(map[string][]*user_model.User)
|
||||||
msg := sender_service.NewMessageFrom(
|
for _, user := range recipients {
|
||||||
recipient.Email,
|
langMap[user.Language] = append(langMap[user.Language], user)
|
||||||
fromDisplayName(sender),
|
}
|
||||||
setting.MailService.FromEmail,
|
for lang, tos := range langMap {
|
||||||
subject,
|
locale := translation.NewLocale(lang)
|
||||||
mailBody.String(),
|
var mailBody bytes.Buffer
|
||||||
)
|
if err := bodyTemplates.ExecuteTemplate(&mailBody, tplWorkflowRun, map[string]any{
|
||||||
msg.Info = subject
|
"Subject": subject,
|
||||||
for k, v := range generateSenderRecipientHeaders(sender, recipient) {
|
"Repo": repo,
|
||||||
msg.SetHeader(k, v)
|
"Run": run,
|
||||||
}
|
"Jobs": jobs,
|
||||||
for k, v := range headers {
|
"locale": locale,
|
||||||
msg.SetHeader(k, v)
|
"Language": locale.Language(),
|
||||||
}
|
}); err != nil {
|
||||||
msg.SetHeader("Message-ID", messageID)
|
log.Error("ExecuteTemplate [%s]: %v", tplWorkflowRun, err)
|
||||||
msgs = append(msgs, msg)
|
}
|
||||||
|
msgs := make([]*sender_service.Message, 0, len(tos))
|
||||||
|
for _, rec := range tos {
|
||||||
|
msg := sender_service.NewMessageFrom(
|
||||||
|
rec.Email,
|
||||||
|
displayName,
|
||||||
|
setting.MailService.FromEmail,
|
||||||
|
subject,
|
||||||
|
mailBody.String(),
|
||||||
|
)
|
||||||
|
msg.Info = subject
|
||||||
|
for k, v := range generateSenderRecipientHeaders(sender, rec) {
|
||||||
|
msg.SetHeader(k, v)
|
||||||
|
}
|
||||||
|
for k, v := range headers {
|
||||||
|
msg.SetHeader(k, v)
|
||||||
|
}
|
||||||
|
msg.SetHeader("Message-ID", messageID)
|
||||||
|
msgs = append(msgs, msg)
|
||||||
|
}
|
||||||
|
SendAsync(msgs...)
|
||||||
}
|
}
|
||||||
SendAsync(msgs...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func SendActionsWorkflowRunStatusEmail(ctx context.Context, sender *user_model.User, repo *repo_model.Repository, run *actions_model.ActionRun) {
|
func SendActionsWorkflowRunStatusEmail(ctx context.Context, sender *user_model.User, repo *repo_model.Repository, run *actions_model.ActionRun) {
|
||||||
|
|||||||
@ -4,22 +4,27 @@
|
|||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
<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">
|
<meta name="format-detection" content="telephone=no,date=no,address=no,email=no,url=no">
|
||||||
<title>{{.Subject}}</title>
|
<title>{{.Subject}}</title>
|
||||||
|
<style>
|
||||||
|
.footer { font-size: small; color: #666; }
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>{{.Repo.FullName}} {{.Run.WorkflowID}}: {{.Run.Status}}</h1>
|
<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}}
|
||||||
|
</h4>
|
||||||
<ul>
|
<ul>
|
||||||
{{range $index, $job := .Jobs}}
|
{{range $job := .Jobs}}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{$.Run.Link}}/jobs/{{$index}}">
|
{{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}}
|
||||||
{{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
|
<div class="footer">
|
||||||
<p>
|
<p>
|
||||||
---
|
---
|
||||||
<br>
|
<br>
|
||||||
<a href="{{.Run.Link}}">{{.locale.Tr "mail.view_it_on" AppName}}</a>.
|
<a href="{{.Run.HTMLURL}}">{{.locale.Tr "mail.view_it_on" AppName}}</a>.
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user