Skip to content

Commit 4ab7928

Browse files
committed
mail notification implement interface
1 parent e5228b8 commit 4ab7928

File tree

5 files changed

+133
-9
lines changed

5 files changed

+133
-9
lines changed

models/issue.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,6 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, assigneeIDs []in
11211121
}); err != nil {
11221122
log.Error(4, "NotifyWatchers: %v", err)
11231123
}
1124-
if err = issue.MailParticipants(); err != nil {
1125-
log.Error(4, "MailParticipants: %v", err)
1126-
}
11271124

11281125
mode, _ := AccessLevel(issue.Poster, issue.Repo)
11291126
if err = PrepareWebhooks(repo, HookEventIssues, &api.IssuePayload{

models/issue_comment.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,11 @@ func (c *Comment) LoadDepIssueDetails() (err error) {
361361

362362
// MailParticipants sends new comment emails to repository watchers
363363
// and mentioned people.
364-
func (c *Comment) MailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
364+
func (c *Comment) MailParticipants(opType ActionType, issue *Issue) (err error) {
365+
return c.mailParticipants(x, opType, issue)
366+
}
367+
368+
func (c *Comment) mailParticipants(e Engine, opType ActionType, issue *Issue) (err error) {
365369
mentions := markup.FindAllMentions(c.Content)
366370
if err = UpdateIssueMentions(e, c.IssueID, mentions); err != nil {
367371
return fmt.Errorf("UpdateIssueMentions [%d]: %v", c.IssueID, err)
@@ -632,9 +636,6 @@ func sendCreateCommentAction(e *xorm.Session, opts *CreateCommentOptions, commen
632636
if err = notifyWatchers(e, act); err != nil {
633637
log.Error(4, "notifyWatchers: %v", err)
634638
}
635-
if err = comment.MailParticipants(e, act.OpType, opts.Issue); err != nil {
636-
log.Error(4, "MailParticipants: %v", err)
637-
}
638639
}
639640
return nil
640641
}

models/pull.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,8 +845,6 @@ func NewPullRequest(repo *Repository, pull *Issue, labelIDs []int64, uuids []str
845845
IsPrivate: repo.IsPrivate,
846846
}); err != nil {
847847
log.Error(4, "NotifyWatchers: %v", err)
848-
} else if err = pull.MailParticipants(); err != nil {
849-
log.Error(4, "MailParticipants: %v", err)
850848
}
851849

852850
pr.Issue = pull

modules/notification/mail/mail.go

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package mail
6+
7+
import (
8+
"code.gitea.io/git"
9+
"code.gitea.io/gitea/models"
10+
"code.gitea.io/gitea/modules/log"
11+
"code.gitea.io/gitea/modules/notification/base"
12+
)
13+
14+
type mailNotifier struct {
15+
}
16+
17+
var (
18+
_ base.Notifier = &mailNotifier{}
19+
)
20+
21+
// NewNotifier create a new mailNotifier notifier
22+
func NewNotifier() base.Notifier {
23+
return &mailNotifier{}
24+
}
25+
26+
func (m *mailNotifier) Run() {
27+
}
28+
29+
func (m *mailNotifier) NotifyCreateIssueComment(doer *models.User, repo *models.Repository,
30+
issue *models.Issue, comment *models.Comment) {
31+
var act models.ActionType
32+
if comment.Type == models.CommentTypeClose {
33+
act = models.ActionCloseIssue
34+
} else if comment.Type == models.CommentTypeReopen {
35+
act = models.ActionReopenIssue
36+
} else if comment.Type == models.CommentTypeComment {
37+
act = models.ActionCommentIssue
38+
} else if comment.Type == models.CommentTypeCode {
39+
act = models.ActionCommentIssue
40+
}
41+
42+
if err := comment.MailParticipants(act, issue); err != nil {
43+
log.Error(4, "MailParticipants: %v", err)
44+
}
45+
}
46+
47+
func (m *mailNotifier) NotifyNewIssue(issue *models.Issue) {
48+
if err := issue.MailParticipants(); err != nil {
49+
log.Error(4, "MailParticipants: %v", err)
50+
}
51+
}
52+
53+
func (m *mailNotifier) NotifyIssueChangeStatus(doer *models.User, issue *models.Issue, isClosed bool) {
54+
if err := issue.MailParticipants(); err != nil {
55+
log.Error(4, "MailParticipants: %v", err)
56+
}
57+
}
58+
59+
func (m *mailNotifier) NotifyNewPullRequest(pr *models.PullRequest) {
60+
if err := pr.Issue.MailParticipants(); err != nil {
61+
log.Error(4, "MailParticipants: %v", err)
62+
}
63+
}
64+
65+
func (m *mailNotifier) NotifyPullRequestReview(pr *models.PullRequest, r *models.Review, comment *models.Comment) {
66+
var act models.ActionType
67+
if comment.Type == models.CommentTypeClose {
68+
act = models.ActionCloseIssue
69+
} else if comment.Type == models.CommentTypeReopen {
70+
act = models.ActionReopenIssue
71+
} else if comment.Type == models.CommentTypeComment {
72+
act = models.ActionCommentIssue
73+
}
74+
if err := comment.MailParticipants(act, pr.Issue); err != nil {
75+
log.Error(4, "MailParticipants: %v", err)
76+
}
77+
}
78+
79+
func (m *mailNotifier) NotifyMergePullRequest(pr *models.PullRequest, doer *models.User, baseRepo *git.Repository) {
80+
}
81+
82+
func (m *mailNotifier) NotifyUpdateComment(doer *models.User, c *models.Comment, oldContent string) {
83+
}
84+
85+
func (m *mailNotifier) NotifyDeleteComment(doer *models.User, c *models.Comment) {
86+
}
87+
88+
func (m *mailNotifier) NotifyDeleteRepository(doer *models.User, repo *models.Repository) {
89+
}
90+
91+
func (m *mailNotifier) NotifyForkRepository(doer *models.User, oldRepo, repo *models.Repository) {
92+
}
93+
94+
func (m *mailNotifier) NotifyNewRelease(rel *models.Release) {
95+
}
96+
97+
func (m *mailNotifier) NotifyUpdateRelease(doer *models.User, rel *models.Release) {
98+
}
99+
100+
func (m *mailNotifier) NotifyDeleteRelease(doer *models.User, rel *models.Release) {
101+
}
102+
103+
func (m *mailNotifier) NotifyIssueChangeMilestone(doer *models.User, issue *models.Issue) {
104+
}
105+
106+
func (m *mailNotifier) NotifyIssueChangeContent(doer *models.User, issue *models.Issue, oldContent string) {
107+
}
108+
109+
func (m *mailNotifier) NotifyIssueChangeAssignee(doer *models.User, issue *models.Issue, removed bool) {
110+
}
111+
112+
func (m *mailNotifier) NotifyIssueClearLabels(doer *models.User, issue *models.Issue) {
113+
}
114+
115+
func (m *mailNotifier) NotifyIssueChangeTitle(doer *models.User, issue *models.Issue, oldTitle string) {
116+
}
117+
118+
func (m *mailNotifier) NotifyIssueChangeLabels(doer *models.User, issue *models.Issue,
119+
addedLabels []*models.Label, removedLabels []*models.Label) {
120+
}
121+
122+
func (m *mailNotifier) NotifyCreateRepository(doer *models.User, u *models.User, repo *models.Repository) {
123+
}
124+
125+
func (m *mailNotifier) NotifyMigrateRepository(doer *models.User, u *models.User, repo *models.Repository) {
126+
}

modules/notification/notification.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"code.gitea.io/git"
99
"code.gitea.io/gitea/models"
1010
"code.gitea.io/gitea/modules/notification/base"
11+
"code.gitea.io/gitea/modules/notification/mail"
1112
"code.gitea.io/gitea/modules/notification/ui"
1213
)
1314

@@ -23,6 +24,7 @@ func RegisterNotifier(notifier base.Notifier) {
2324

2425
func init() {
2526
RegisterNotifier(ui.NewNotifier())
27+
RegisterNotifier(mail.NewNotifier())
2628
}
2729

2830
// NotifyCreateIssueComment notifies issue comment related message to notifiers

0 commit comments

Comments
 (0)