Skip to content

Commit ebde1d3

Browse files
committed
Change email notify way
1 parent bd363e5 commit ebde1d3

File tree

3 files changed

+52
-53
lines changed

3 files changed

+52
-53
lines changed

models/issue_comment.go

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -579,55 +579,6 @@ func (c *Comment) LoadPushCommits() (err error) {
579579
return err
580580
}
581581

582-
// LoadPullPushDefaultNotify load default notify message in Content
583-
// with Mardown style for Pull Push commits comment
584-
func (c *Comment) LoadPullPushDefaultNotify() (err error) {
585-
if c.Type != CommentTypePullPush {
586-
return nil
587-
}
588-
if err = c.LoadIssue(); err != nil {
589-
return
590-
}
591-
if err = c.Issue.LoadRepo(); err != nil {
592-
return
593-
}
594-
if err = c.Issue.LoadPullRequest(); err != nil {
595-
return
596-
}
597-
598-
message := "@" + c.Poster.Name
599-
if c.IsForcePush {
600-
commitIDs := strings.Split(c.Content, ":")
601-
message += " force-pushed the " + c.Issue.PullRequest.HeadBranch + " branch from " + commitIDs[0] + " to " + commitIDs[1]
602-
} else {
603-
if c.Commits == nil {
604-
repoPath := c.Issue.Repo.RepoPath()
605-
gitRepo, err := git.OpenRepository(repoPath)
606-
if err != nil {
607-
return err
608-
}
609-
defer gitRepo.Close()
610-
commitIDs := strings.Split(c.Content, ":")
611-
c.Commits = gitRepo.GetCommitsFromIDs(commitIDs)
612-
}
613-
614-
if c.Commits.Len() == 1 {
615-
message += fmt.Sprintf(" pushed 1 commit to %s: \n ", c.Issue.Repo.Name)
616-
} else {
617-
message += fmt.Sprintf(" pushed %d commits to %s: \n ", c.Commits.Len(), c.Issue.Repo.Name)
618-
}
619-
620-
for e := c.Commits.Front(); e != nil; e = e.Next() {
621-
commitMsg := strings.Split(e.Value.(*git.Commit).Message(), "\n")[0]
622-
message += "* " + e.Value.(*git.Commit).ID.String()[0:10] + " - " + commitMsg + " \n"
623-
}
624-
}
625-
626-
c.Content = message
627-
628-
return
629-
}
630-
631582
func createComment(e *xorm.Session, opts *CreateCommentOptions) (_ *Comment, err error) {
632583
var LabelID int64
633584
if opts.Label != nil {

modules/notification/mail/mail.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,27 @@ func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *mode
121121
}
122122

123123
func (m *mailNotifier) NotifyPullRequestPushCommits(doer *models.User, pr *models.PullRequest, comment *models.Comment) {
124-
if err := comment.LoadPullPushDefaultNotify(); err != nil {
125-
log.Error("comment.loadPullPushDefaultNotify: %v", err)
126-
comment.Content = " "
124+
var err error
125+
if err = comment.LoadIssue(); err != nil {
126+
log.Error("comment.LoadIssue: %v", err)
127+
return
128+
}
129+
if err = comment.Issue.LoadRepo(); err != nil {
130+
log.Error("comment.Issue.LoadRepo: %v", err)
131+
return
132+
}
133+
if err = comment.Issue.LoadPullRequest(); err != nil {
134+
log.Error("comment.Issue.LoadPullRequest: %v", err)
135+
return
136+
}
137+
if err = comment.Issue.PullRequest.LoadBaseRepo(); err != nil {
138+
log.Error("comment.Issue.PullRequest.LoadBaseRepo: %v", err)
139+
return
140+
}
141+
if err := comment.LoadPushCommits(); err != nil {
142+
log.Error("comment.LoadPushCommits: %v", err)
127143
}
144+
comment.Content = ""
128145

129146
m.NotifyCreateIssueComment(doer, comment.Issue.Repo, comment.Issue, comment)
130147
}

templates/mail/issue/default.tmpl

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717

1818
<body>
1919
{{if .IsMention}}<p><b>@{{.Doer.Name}}</b> mentioned you:</p>{{end}}
20+
{{if eq .Comment.Type 29}}
21+
<p>
22+
<b>{{.Doer.Name}}</b>
23+
{{if .Comment.IsForcePush}}
24+
{{ $oldCommitLink:= printf "%s%s/%s/commit/%s" AppUrl .Comment.Issue.PullRequest.BaseRepo.OwnerName .Comment.Issue.PullRequest.BaseRepo.Name .Comment.OldCommit}}
25+
{{ $newCommitLink:= printf "%s%s/%s/commit/%s" AppUrl .Comment.Issue.PullRequest.BaseRepo.OwnerName .Comment.Issue.PullRequest.BaseRepo.Name .Comment.NewCommit}}
26+
force-pushed the <b>{{.Comment.Issue.PullRequest.HeadBranch}}</b> from
27+
<a href="{{$oldCommitLink}}"><b>{{ShortSha .Comment.OldCommit}}</b></a>
28+
to
29+
<a href="{{$newCommitLink}}"><b>{{ShortSha .Comment.NewCommit}}</b></a>.
30+
{{else}}
31+
{{if eq .Comment.Commits.Len 1}}
32+
{{printf "pushed 1 commit to %s:" .Comment.Issue.PullRequest.HeadBranch}}
33+
{{else}}
34+
{{printf "pushed %d commits to %s:" .Comment.Commits.Len .Comment.Issue.PullRequest.HeadBranch}}
35+
{{end}}
36+
{{end}}
37+
</p>
38+
{{end}}
2039
<p>
2140
{{if eq .ActionName "close"}}
2241
Closed #{{.Issue.Index}}.
@@ -46,7 +65,19 @@
4665
<pre>{{.Patch}}</pre>
4766
<div>{{.RenderedContent | Safe}}</div>
4867
</div>
49-
{{end -}}
68+
{{end -}}
69+
{{if eq .Comment.Type 29}}
70+
{{ $r:= List .Comment.Commits}}
71+
<ul>
72+
{{range $r}}
73+
<li>
74+
<a href="{{AppUrl}}{{$.Comment.Issue.PullRequest.BaseRepo.OwnerName}}/{{$.Comment.Issue.PullRequest.BaseRepo.Name}}/commit/{{.ID}}">
75+
{{ShortSha .ID.String}}
76+
</a> - {{.Summary}}
77+
</li>
78+
{{end}}
79+
</ul>
80+
{{end}}
5081
</p>
5182
<div class="footer">
5283
<p>

0 commit comments

Comments
 (0)