forked from Shiloh/githaven
Fix incorrect message id for releaes email (#30825)
Make generateMessageIDForRelease outputs the same format as generateMessageIDForIssue (old `createReference`)
This commit is contained in:
parent
6f89d5e3a0
commit
677032d36a
@ -289,8 +289,8 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Make sure to compose independent messages to avoid leaking user emails
|
// Make sure to compose independent messages to avoid leaking user emails
|
||||||
msgID := createReference(ctx.Issue, ctx.Comment, ctx.ActionType)
|
msgID := generateMessageIDForIssue(ctx.Issue, ctx.Comment, ctx.ActionType)
|
||||||
reference := createReference(ctx.Issue, nil, activities_model.ActionType(0))
|
reference := generateMessageIDForIssue(ctx.Issue, nil, activities_model.ActionType(0))
|
||||||
|
|
||||||
var replyPayload []byte
|
var replyPayload []byte
|
||||||
if ctx.Comment != nil {
|
if ctx.Comment != nil {
|
||||||
@ -362,7 +362,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
|
|||||||
return msgs, nil
|
return msgs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func createReference(issue *issues_model.Issue, comment *issues_model.Comment, actionType activities_model.ActionType) string {
|
func generateMessageIDForIssue(issue *issues_model.Issue, comment *issues_model.Comment, actionType activities_model.ActionType) string {
|
||||||
var path string
|
var path string
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
path = "pulls"
|
path = "pulls"
|
||||||
@ -389,6 +389,10 @@ func createReference(issue *issues_model.Issue, comment *issues_model.Comment, a
|
|||||||
return fmt.Sprintf("<%s/%s/%d%s@%s>", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
|
return fmt.Sprintf("<%s/%s/%d%s@%s>", issue.Repo.FullName(), path, issue.Index, extra, setting.Domain)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func generateMessageIDForRelease(release *repo_model.Release) string {
|
||||||
|
return fmt.Sprintf("<%s/releases/%d@%s>", release.Repo.FullName(), release.ID, setting.Domain)
|
||||||
|
}
|
||||||
|
|
||||||
func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *user_model.User) map[string]string {
|
func generateAdditionalHeaders(ctx *mailCommentContext, reason string, recipient *user_model.User) map[string]string {
|
||||||
repo := ctx.Issue.Repo
|
repo := ctx.Issue.Repo
|
||||||
|
|
||||||
|
@ -86,11 +86,11 @@ func mailNewRelease(ctx context.Context, lang string, tos []string, rel *repo_mo
|
|||||||
|
|
||||||
msgs := make([]*Message, 0, len(tos))
|
msgs := make([]*Message, 0, len(tos))
|
||||||
publisherName := rel.Publisher.DisplayName()
|
publisherName := rel.Publisher.DisplayName()
|
||||||
relURL := "<" + rel.HTMLURL() + ">"
|
msgID := generateMessageIDForRelease(rel)
|
||||||
for _, to := range tos {
|
for _, to := range tos {
|
||||||
msg := NewMessageFrom(to, publisherName, setting.MailService.FromEmail, subject, mailBody.String())
|
msg := NewMessageFrom(to, publisherName, setting.MailService.FromEmail, subject, mailBody.String())
|
||||||
msg.Info = subject
|
msg.Info = subject
|
||||||
msg.SetHeader("Message-ID", relURL)
|
msg.SetHeader("Message-ID", msgID)
|
||||||
msgs = append(msgs, msg)
|
msgs = append(msgs, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,7 +288,7 @@ func TestGenerateAdditionalHeaders(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_createReference(t *testing.T) {
|
func TestGenerateMessageIDForIssue(t *testing.T) {
|
||||||
_, _, issue, comment := prepareMailerTest(t)
|
_, _, issue, comment := prepareMailerTest(t)
|
||||||
_, _, pullIssue, _ := prepareMailerTest(t)
|
_, _, pullIssue, _ := prepareMailerTest(t)
|
||||||
pullIssue.IsPull = true
|
pullIssue.IsPull = true
|
||||||
@ -388,10 +388,18 @@ func Test_createReference(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got := createReference(tt.args.issue, tt.args.comment, tt.args.actionType)
|
got := generateMessageIDForIssue(tt.args.issue, tt.args.comment, tt.args.actionType)
|
||||||
if !strings.HasPrefix(got, tt.prefix) {
|
if !strings.HasPrefix(got, tt.prefix) {
|
||||||
t.Errorf("createReference() = %v, want %v", got, tt.prefix)
|
t.Errorf("generateMessageIDForIssue() = %v, want %v", got, tt.prefix)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGenerateMessageIDForRelease(t *testing.T) {
|
||||||
|
msgID := generateMessageIDForRelease(&repo_model.Release{
|
||||||
|
ID: 1,
|
||||||
|
Repo: &repo_model.Repository{OwnerName: "owner", Name: "repo"},
|
||||||
|
})
|
||||||
|
assert.Equal(t, "<owner/repo/releases/1@localhost>", msgID)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user