Skip to content

Commit 061d817

Browse files
committed
MOVE
1 parent de1114b commit 061d817

23 files changed

+73
-62
lines changed

services/mailer/mail_issue_common.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,18 +260,18 @@ func actionToTemplate(issue *issues_model.Issue, actionType activities_model.Act
260260
}
261261
}
262262

263-
template = typeName + "/" + name
263+
template = "repo/" + typeName + "/" + name
264264
ok := LoadedTemplates().BodyTemplates.Lookup(template) != nil
265265
if !ok && typeName != "issue" {
266-
template = "issue/" + name
266+
template = "repo/issue/" + name
267267
ok = LoadedTemplates().BodyTemplates.Lookup(template) != nil
268268
}
269269
if !ok {
270-
template = typeName + "/default"
270+
template = "repo/" + typeName + "/default"
271271
ok = LoadedTemplates().BodyTemplates.Lookup(template) != nil
272272
}
273273
if !ok {
274-
template = "issue/default"
274+
template = "repo/issue/default"
275275
}
276276
return typeName, name, template
277277
}

services/mailer/mail_release.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
sender_service "code.gitea.io/gitea/services/mailer/sender"
2020
)
2121

22-
const tplNewReleaseMail templates.TplName = "release"
22+
const tplNewReleaseMail templates.TplName = "repo/release"
2323

2424
func generateMessageIDForRelease(release *repo_model.Release) string {
2525
return fmt.Sprintf("<%s/releases/%d@%s>", release.Repo.FullName(), release.ID, setting.Domain)

services/mailer/mail_repo.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ import (
1111
"code.gitea.io/gitea/models/organization"
1212
repo_model "code.gitea.io/gitea/models/repo"
1313
user_model "code.gitea.io/gitea/models/user"
14+
"code.gitea.io/gitea/modules/log"
1415
"code.gitea.io/gitea/modules/setting"
1516
"code.gitea.io/gitea/modules/templates"
1617
"code.gitea.io/gitea/modules/translation"
1718
sender_service "code.gitea.io/gitea/services/mailer/sender"
1819
)
1920

20-
const mailRepoTransferNotify templates.TplName = "notify/repo_transfer"
21+
const (
22+
mailNotifyCollaborator templates.TplName = "repo/collaborator"
23+
mailRepoTransferNotify templates.TplName = "repo/transfer"
24+
)
2125

2226
// SendRepoTransferNotifyMail triggers a notification e-mail when a pending repository transfer was created
2327
func SendRepoTransferNotifyMail(ctx context.Context, doer, newOwner *user_model.User, repo *repo_model.Repository) error {
@@ -91,3 +95,34 @@ func sendRepoTransferNotifyMailPerLang(lang string, newOwner, doer *user_model.U
9195

9296
return nil
9397
}
98+
99+
// SendCollaboratorMail sends mail notification to new collaborator.
100+
func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) {
101+
if setting.MailService == nil || !u.IsActive {
102+
// No mail service configured OR the user is inactive
103+
return
104+
}
105+
locale := translation.NewLocale(u.Language)
106+
repoName := repo.FullName()
107+
108+
subject := locale.TrString("mail.repo.collaborator.added.subject", doer.DisplayName(), repoName)
109+
data := map[string]any{
110+
"locale": locale,
111+
"Subject": subject,
112+
"RepoName": repoName,
113+
"Link": repo.HTMLURL(),
114+
"Language": locale.Language(),
115+
}
116+
117+
var content bytes.Buffer
118+
119+
if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&content, string(mailNotifyCollaborator), data); err != nil {
120+
log.Error("Template: %v", err)
121+
return
122+
}
123+
124+
msg := sender_service.NewMessage(u.EmailTo(), subject, content.String())
125+
msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.ID)
126+
127+
SendAsync(msg)
128+
}

services/mailer/mail_team_invite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
sender_service "code.gitea.io/gitea/services/mailer/sender"
2020
)
2121

22-
const tplTeamInviteMail templates.TplName = "team_invite"
22+
const tplTeamInviteMail templates.TplName = "org/team_invite"
2323

2424
// MailTeamInvite sends team invites
2525
func MailTeamInvite(ctx context.Context, inviter *user_model.User, team *org_model.Team, invite *org_model.TeamInvite) error {

services/mailer/mail_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func TestComposeIssueComment(t *testing.T) {
116116
setting.IncomingEmail.Enabled = true
117117
defer func() { setting.IncomingEmail.Enabled = false }()
118118

119-
prepareMailTemplates("issue/comment", subjectTpl, bodyTpl)
119+
prepareMailTemplates("repo/issue/comment", subjectTpl, bodyTpl)
120120

121121
recipients := []*user_model.User{{Name: "Test", Email: "[email protected]"}, {Name: "Test2", Email: "[email protected]"}}
122122
msgs, err := composeIssueCommentMessages(t.Context(), &mailComment{
@@ -161,7 +161,7 @@ func TestComposeIssueComment(t *testing.T) {
161161
func TestMailMentionsComment(t *testing.T) {
162162
doer, _, issue, comment := prepareMailerTest(t)
163163
comment.Poster = doer
164-
prepareMailTemplates("issue/comment", subjectTpl, bodyTpl)
164+
prepareMailTemplates("repo/issue/comment", subjectTpl, bodyTpl)
165165
mails := 0
166166

167167
defer test.MockVariableValue(&SendAsync, func(msgs ...*sender_service.Message) {
@@ -176,7 +176,7 @@ func TestMailMentionsComment(t *testing.T) {
176176
func TestComposeIssueMessage(t *testing.T) {
177177
doer, _, issue, _ := prepareMailerTest(t)
178178

179-
prepareMailTemplates("issue/new", subjectTpl, bodyTpl)
179+
prepareMailTemplates("repo/issue/new", subjectTpl, bodyTpl)
180180
recipients := []*user_model.User{{Name: "Test", Email: "[email protected]"}, {Name: "Test2", Email: "[email protected]"}}
181181
msgs, err := composeIssueCommentMessages(t.Context(), &mailComment{
182182
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
@@ -205,14 +205,14 @@ func TestTemplateSelection(t *testing.T) {
205205
doer, repo, issue, comment := prepareMailerTest(t)
206206
recipients := []*user_model.User{{Name: "Test", Email: "[email protected]"}}
207207

208-
prepareMailTemplates("issue/default", "issue/default/subject", "issue/default/body")
208+
prepareMailTemplates("repo/issue/default", "repo/issue/default/subject", "repo/issue/default/body")
209209

210-
texttmpl.Must(LoadedTemplates().SubjectTemplates.New("issue/new").Parse("issue/new/subject"))
211-
texttmpl.Must(LoadedTemplates().SubjectTemplates.New("pull/comment").Parse("pull/comment/subject"))
212-
texttmpl.Must(LoadedTemplates().SubjectTemplates.New("issue/close").Parse("")) // Must default to a fallback subject
213-
template.Must(LoadedTemplates().BodyTemplates.New("issue/new").Parse("issue/new/body"))
214-
template.Must(LoadedTemplates().BodyTemplates.New("pull/comment").Parse("pull/comment/body"))
215-
template.Must(LoadedTemplates().BodyTemplates.New("issue/close").Parse("issue/close/body"))
210+
texttmpl.Must(LoadedTemplates().SubjectTemplates.New("repo/issue/new").Parse("repo/issue/new/subject"))
211+
texttmpl.Must(LoadedTemplates().SubjectTemplates.New("repo/pull/comment").Parse("repo/pull/comment/subject"))
212+
texttmpl.Must(LoadedTemplates().SubjectTemplates.New("repo/issue/close").Parse("")) // Must default to a fallback subject
213+
template.Must(LoadedTemplates().BodyTemplates.New("repo/issue/new").Parse("repo/issue/new/body"))
214+
template.Must(LoadedTemplates().BodyTemplates.New("repo/pull/comment").Parse("repo/pull/comment/body"))
215+
template.Must(LoadedTemplates().BodyTemplates.New("repo/issue/close").Parse("repo/issue/close/body"))
216216

217217
expect := func(t *testing.T, msg *sender_service.Message, expSubject, expBody string) {
218218
subject := msg.ToMessage().GetGenHeader("Subject")
@@ -227,27 +227,27 @@ func TestTemplateSelection(t *testing.T) {
227227
Issue: issue, Doer: doer, ActionType: activities_model.ActionCreateIssue,
228228
Content: "test body",
229229
}, recipients, false, "TestTemplateSelection")
230-
expect(t, msg, "issue/new/subject", "issue/new/body")
230+
expect(t, msg, "repo/issue/new/subject", "repo/issue/new/body")
231231

232232
msg = testComposeIssueCommentMessage(t, &mailComment{
233233
Issue: issue, Doer: doer, ActionType: activities_model.ActionCommentIssue,
234234
Content: "test body", Comment: comment,
235235
}, recipients, false, "TestTemplateSelection")
236-
expect(t, msg, "issue/default/subject", "issue/default/body")
236+
expect(t, msg, "repo/issue/default/subject", "repo/issue/default/body")
237237

238238
pull := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 2, Repo: repo, Poster: doer})
239239
comment = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 4, Issue: pull})
240240
msg = testComposeIssueCommentMessage(t, &mailComment{
241241
Issue: pull, Doer: doer, ActionType: activities_model.ActionCommentPull,
242242
Content: "test body", Comment: comment,
243243
}, recipients, false, "TestTemplateSelection")
244-
expect(t, msg, "pull/comment/subject", "pull/comment/body")
244+
expect(t, msg, "repo/pull/comment/subject", "repo/pull/comment/body")
245245

246246
msg = testComposeIssueCommentMessage(t, &mailComment{
247247
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
248248
Content: "test body", Comment: comment,
249249
}, recipients, false, "TestTemplateSelection")
250-
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body")
250+
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "repo/issue/close/body")
251251
}
252252

253253
func TestTemplateServices(t *testing.T) {
@@ -257,7 +257,7 @@ func TestTemplateServices(t *testing.T) {
257257
expect := func(t *testing.T, issue *issues_model.Issue, comment *issues_model.Comment, doer *user_model.User,
258258
actionType activities_model.ActionType, fromMention bool, tplSubject, tplBody, expSubject, expBody string,
259259
) {
260-
prepareMailTemplates("issue/default", tplSubject, tplBody)
260+
prepareMailTemplates("repo/issue/default", tplSubject, tplBody)
261261
recipients := []*user_model.User{{Name: "Test", Email: "[email protected]"}}
262262
msg := testComposeIssueCommentMessage(t, &mailComment{
263263
Issue: issue, Doer: doer, ActionType: actionType,
@@ -524,7 +524,7 @@ func TestEmbedBase64Images(t *testing.T) {
524524
att2ImgBase64 := fmt.Sprintf(`<img src="%s"/>`, att2Base64)
525525

526526
t.Run("ComposeMessage", func(t *testing.T) {
527-
prepareMailTemplates("issue/new", subjectTpl, bodyTpl)
527+
prepareMailTemplates("repo/issue/new", subjectTpl, bodyTpl)
528528

529529
issue.Content = fmt.Sprintf(`MSG-BEFORE <image src="attachments/%s"> MSG-AFTER`, att1.UUID)
530530
require.NoError(t, issues_model.UpdateIssueCols(t.Context(), issue, "content"))

services/mailer/mail_user.go

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"bytes"
88
"fmt"
99

10-
repo_model "code.gitea.io/gitea/models/repo"
1110
user_model "code.gitea.io/gitea/models/user"
1211
"code.gitea.io/gitea/modules/log"
1312
"code.gitea.io/gitea/modules/setting"
@@ -18,11 +17,10 @@ import (
1817
)
1918

2019
const (
21-
mailAuthActivate templates.TplName = "auth/activate"
22-
mailAuthActivateEmail templates.TplName = "auth/activate_email"
23-
mailAuthResetPassword templates.TplName = "auth/reset_passwd"
24-
mailAuthRegisterNotify templates.TplName = "auth/register_notify"
25-
mailNotifyCollaborator templates.TplName = "notify/collaborator"
20+
mailAuthActivate templates.TplName = "user/auth/activate"
21+
mailAuthActivateEmail templates.TplName = "user/auth/activate_email"
22+
mailAuthResetPassword templates.TplName = "user/auth/reset_passwd"
23+
mailAuthRegisterNotify templates.TplName = "user/auth/register_notify"
2624
)
2725

2826
// sendUserMail sends a mail to the user
@@ -128,34 +126,3 @@ func SendRegisterNotifyMail(u *user_model.User) {
128126

129127
SendAsync(msg)
130128
}
131-
132-
// SendCollaboratorMail sends mail notification to new collaborator.
133-
func SendCollaboratorMail(u, doer *user_model.User, repo *repo_model.Repository) {
134-
if setting.MailService == nil || !u.IsActive {
135-
// No mail service configured OR the user is inactive
136-
return
137-
}
138-
locale := translation.NewLocale(u.Language)
139-
repoName := repo.FullName()
140-
141-
subject := locale.TrString("mail.repo.collaborator.added.subject", doer.DisplayName(), repoName)
142-
data := map[string]any{
143-
"locale": locale,
144-
"Subject": subject,
145-
"RepoName": repoName,
146-
"Link": repo.HTMLURL(),
147-
"Language": locale.Language(),
148-
}
149-
150-
var content bytes.Buffer
151-
152-
if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&content, string(mailNotifyCollaborator), data); err != nil {
153-
log.Error("Template: %v", err)
154-
return
155-
}
156-
157-
msg := sender_service.NewMessage(u.EmailTo(), subject, content.String())
158-
msg.Info = fmt.Sprintf("UID: %d, add collaborator", u.ID)
159-
160-
SendAsync(msg)
161-
}

services/mailer/mail_workflow_run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ import (
1515
"code.gitea.io/gitea/modules/base"
1616
"code.gitea.io/gitea/modules/log"
1717
"code.gitea.io/gitea/modules/setting"
18+
"code.gitea.io/gitea/modules/templates"
1819
"code.gitea.io/gitea/modules/translation"
1920
"code.gitea.io/gitea/services/convert"
2021
sender_service "code.gitea.io/gitea/services/mailer/sender"
2122
)
2223

23-
const tplWorkflowRun = "notify/workflow_run"
24+
const tplWorkflowRun templates.TplName = "repo/actions/workflow_run"
2425

2526
type convertedWorkflowJob struct {
2627
HTMLURL string
@@ -103,7 +104,7 @@ func composeAndSendActionsWorkflowRunStatusEmail(ctx context.Context, repo *repo
103104
runStatusText = "All jobs have been cancelled"
104105
}
105106
var mailBody bytes.Buffer
106-
if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&mailBody, tplWorkflowRun, map[string]any{
107+
if err := LoadedTemplates().BodyTemplates.ExecuteTemplate(&mailBody, string(tplWorkflowRun), map[string]any{
107108
"Subject": subject,
108109
"Repo": repo,
109110
"Run": run,
File renamed without changes.

0 commit comments

Comments
 (0)