mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-11-04 04:14:01 +01:00 
			
		
		
		
	MAILER
This commit is contained in:
		
							parent
							
								
									a63093528a
								
							
						
					
					
						commit
						1f6c68d572
					
				@ -9,6 +9,8 @@ import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"sort"
 | 
			
		||||
 | 
			
		||||
	"code.gitea.io/gitea/modules/translation"
 | 
			
		||||
 | 
			
		||||
	actions_model "code.gitea.io/gitea/models/actions"
 | 
			
		||||
	"code.gitea.io/gitea/models/db"
 | 
			
		||||
	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) {
 | 
			
		||||
	msgs := make([]*sender_service.Message, 0, len(recipients))
 | 
			
		||||
 | 
			
		||||
	messageID := generateMessageIDForActionsWorkflowRunStatusEmail(repo, run)
 | 
			
		||||
	headers := generateMetadataHeaders(repo)
 | 
			
		||||
 | 
			
		||||
@ -62,35 +62,46 @@ func sendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo_model.Rep
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var mailBody bytes.Buffer
 | 
			
		||||
	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)
 | 
			
		||||
	}
 | 
			
		||||
	displayName := fromDisplayName(sender)
 | 
			
		||||
 | 
			
		||||
	for _, recipient := range recipients {
 | 
			
		||||
		msg := sender_service.NewMessageFrom(
 | 
			
		||||
			recipient.Email,
 | 
			
		||||
			fromDisplayName(sender),
 | 
			
		||||
			setting.MailService.FromEmail,
 | 
			
		||||
			subject,
 | 
			
		||||
			mailBody.String(),
 | 
			
		||||
		)
 | 
			
		||||
		msg.Info = subject
 | 
			
		||||
		for k, v := range generateSenderRecipientHeaders(sender, recipient) {
 | 
			
		||||
			msg.SetHeader(k, v)
 | 
			
		||||
		}
 | 
			
		||||
		for k, v := range headers {
 | 
			
		||||
			msg.SetHeader(k, v)
 | 
			
		||||
		}
 | 
			
		||||
		msg.SetHeader("Message-ID", messageID)
 | 
			
		||||
		msgs = append(msgs, msg)
 | 
			
		||||
	langMap := make(map[string][]*user_model.User)
 | 
			
		||||
	for _, user := range recipients {
 | 
			
		||||
		langMap[user.Language] = append(langMap[user.Language], user)
 | 
			
		||||
	}
 | 
			
		||||
	for lang, tos := range langMap {
 | 
			
		||||
		locale := translation.NewLocale(lang)
 | 
			
		||||
		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(),
 | 
			
		||||
		}); err != nil {
 | 
			
		||||
			log.Error("ExecuteTemplate [%s]: %v", tplWorkflowRun, err)
 | 
			
		||||
		}
 | 
			
		||||
		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) {
 | 
			
		||||
 | 
			
		||||
@ -4,22 +4,27 @@
 | 
			
		||||
	<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>
 | 
			
		||||
	<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>
 | 
			
		||||
	{{range $index, $job := .Jobs}}
 | 
			
		||||
	{{range $job := .Jobs}}
 | 
			
		||||
		<li>
 | 
			
		||||
			<a href="{{$.Run.Link}}/jobs/{{$index}}">
 | 
			
		||||
			{{$job.Status}}: {{$job.Name}}{{if gt $job.Attempt 1}}, Attempt #{{$job.Attempt}}{{end}}
 | 
			
		||||
			</a>
 | 
			
		||||
			{{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}}
 | 
			
		||||
		</li>
 | 
			
		||||
	{{end}}
 | 
			
		||||
	</ul>
 | 
			
		||||
	<div class="footer">
 | 
			
		||||
	<p>
 | 
			
		||||
		---
 | 
			
		||||
		<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>
 | 
			
		||||
	</div>
 | 
			
		||||
</body>
 | 
			
		||||
</html>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user