Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-25 11:16:11 +01:00

mail issue: Display issue type in email header

Currently notification emails for Pull Requests or Issues are
indistinguishable at first glance. This adds the type ("PR" or "Issue")
before the index number.
This commit is contained in:
Thorben Günther 2024-09-24 22:55:30 +02:00
parent 60bcdc8bc3
commit 74403d1f0f
No known key found for this signature in database
GPG key ID: 415CD778D8C5AFED
2 changed files with 15 additions and 4 deletions

View file

@ -19,7 +19,10 @@ import (
) )
func fallbackMailSubject(issue *issues_model.Issue) string { func fallbackMailSubject(issue *issues_model.Issue) string {
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.FullName(), issue.Title, issue.Index) if issue.IsPull {
return fmt.Sprintf("[%s] %s (PR #%d)", issue.Repo.FullName(), issue.Title, issue.Index)
}
return fmt.Sprintf("[%s] %s (Issue #%d)", issue.Repo.FullName(), issue.Title, issue.Index)
} }
type mailCommentContext struct { type mailCommentContext struct {

View file

@ -138,7 +138,7 @@ func TestComposeIssueMessage(t *testing.T) {
references := gomailMsg.GetHeader("References") references := gomailMsg.GetHeader("References")
assert.Len(t, mailto, 1, "exactly one recipient is expected in the To field") assert.Len(t, mailto, 1, "exactly one recipient is expected in the To field")
assert.Equal(t, "[user2/repo1] issue1 (#1)", subject[0]) assert.Equal(t, "[user2/repo1] issue1 (Issue #1)", subject[0])
assert.Equal(t, "<user2/repo1/issues/1@localhost>", inReplyTo[0], "In-Reply-To header doesn't match") assert.Equal(t, "<user2/repo1/issues/1@localhost>", inReplyTo[0], "In-Reply-To header doesn't match")
assert.Equal(t, "<user2/repo1/issues/1@localhost>", references[0], "References header doesn't match") assert.Equal(t, "<user2/repo1/issues/1@localhost>", references[0], "References header doesn't match")
assert.Equal(t, "<user2/repo1/issues/1@localhost>", messageID[0], "Message-ID header doesn't match") assert.Equal(t, "<user2/repo1/issues/1@localhost>", messageID[0], "Message-ID header doesn't match")
@ -293,7 +293,7 @@ func TestTemplateSelection(t *testing.T) {
Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue, Issue: issue, Doer: doer, ActionType: activities_model.ActionCloseIssue,
Content: "test body", Comment: comment, Content: "test body", Comment: comment,
}, recipients, false, "TestTemplateSelection") }, recipients, false, "TestTemplateSelection")
expect(t, msg, "Re: [user2/repo1] issue1 (#1)", "issue/close/body") expect(t, msg, "Re: [user2/repo1] issue1 (Issue #1)", "issue/close/body")
} }
func TestTemplateServices(t *testing.T) { func TestTemplateServices(t *testing.T) {
@ -338,7 +338,7 @@ func TestTemplateServices(t *testing.T) {
expect(t, issue, comment, doer, activities_model.ActionCommentIssue, true, expect(t, issue, comment, doer, activities_model.ActionCommentIssue, true,
"{{.FallbackSubject}}", "{{.FallbackSubject}}",
"//{{.SubjectPrefix}}//", "//{{.SubjectPrefix}}//",
"Re: [user2/repo1] issue1 (#1)", "Re: [user2/repo1] issue1 (Issue #1)",
"//Re: //") "//Re: //")
} }
@ -538,3 +538,11 @@ func TestFromDisplayName(t *testing.T) {
assert.EqualValues(t, "Mister X (by Code IT on [code.it])", fromDisplayName(&user_model.User{FullName: "Mister X", Name: "tmp"})) assert.EqualValues(t, "Mister X (by Code IT on [code.it])", fromDisplayName(&user_model.User{FullName: "Mister X", Name: "tmp"}))
}) })
} }
func TestFallbackSubjectType(t *testing.T) {
_, _, issue, _ := prepareMailerTest(t)
assert.Contains(t, fallbackMailSubject(issue), "Issue")
_, _, pr, _ := prepareMailerTest(t)
pr.IsPull = true
assert.Contains(t, fallbackMailSubject(pr), "PR")
}