From 74403d1f0fc7da1f6a13cee870fe92b7dce75dee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Tue, 24 Sep 2024 22:55:30 +0200 Subject: [PATCH] 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. --- services/mailer/mail_issue.go | 5 ++++- services/mailer/mail_test.go | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/services/mailer/mail_issue.go b/services/mailer/mail_issue.go index fab3315be2..1bb6fdc7a3 100644 --- a/services/mailer/mail_issue.go +++ b/services/mailer/mail_issue.go @@ -19,7 +19,10 @@ import ( ) 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 { diff --git a/services/mailer/mail_test.go b/services/mailer/mail_test.go index 1a9bbc9f16..b2768a2bad 100644 --- a/services/mailer/mail_test.go +++ b/services/mailer/mail_test.go @@ -138,7 +138,7 @@ func TestComposeIssueMessage(t *testing.T) { references := gomailMsg.GetHeader("References") 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, "", inReplyTo[0], "In-Reply-To header doesn't match") assert.Equal(t, "", references[0], "References header doesn't match") assert.Equal(t, "", 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, Content: "test body", Comment: comment, }, 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) { @@ -338,7 +338,7 @@ func TestTemplateServices(t *testing.T) { expect(t, issue, comment, doer, activities_model.ActionCommentIssue, true, "{{.FallbackSubject}}", "//{{.SubjectPrefix}}//", - "Re: [user2/repo1] issue1 (#1)", + "Re: [user2/repo1] issue1 (Issue #1)", "//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"})) }) } + +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") +}