Skip to content

Commit bab067b

Browse files
committed
go-gitea#14559 Reduce amount of email notifications for WIP draft PR's
don't notify repo watchers of WIP draft PR's
1 parent 9e852ed commit bab067b

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

models/notification.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,14 @@ func createOrUpdateIssueNotifications(e Engine, issueID, commentID, notification
162162
for _, id := range issueWatches {
163163
toNotify[id] = struct{}{}
164164
}
165-
166-
repoWatches, err := getRepoWatchersIDs(e, issue.RepoID)
167-
if err != nil {
168-
return err
169-
}
170-
for _, id := range repoWatches {
171-
toNotify[id] = struct{}{}
165+
if !(issue.IsPull && HasWorkInProgressPrefix(issue.Title)) {
166+
repoWatches, err := getRepoWatchersIDs(e, issue.RepoID)
167+
if err != nil {
168+
return err
169+
}
170+
for _, id := range repoWatches {
171+
toNotify[id] = struct{}{}
172+
}
172173
}
173174
issueParticipants, err := issue.getParticipantIDsByIssue(e)
174175
if err != nil {

models/pull.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,9 +589,13 @@ func (pr *PullRequest) IsWorkInProgress() bool {
589589
log.Error("LoadIssue: %v", err)
590590
return false
591591
}
592+
return HasWorkInProgressPrefix(pr.Issue.Title)
593+
}
592594

595+
// HasWorkInProgressPrefix determines if the given PR title has a Work In Progress prefix
596+
func HasWorkInProgressPrefix(title string) bool {
593597
for _, prefix := range setting.Repository.PullRequest.WorkInProgressPrefixes {
594-
if strings.HasPrefix(strings.ToUpper(pr.Issue.Title), prefix) {
598+
if strings.HasPrefix(strings.ToUpper(title), prefix) {
595599
return true
596600
}
597601
}

services/mailer/mail_issue.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type mailCommentContext struct {
2525

2626
// mailIssueCommentToParticipants can be used for both new issue creation and comment.
2727
// This function sends two list of emails:
28-
// 1. Repository watchers and users who are participated in comments.
28+
// 1. Repository watchers (except for WIP pull requests) and users who are participated in comments.
2929
// 2. Users who are not in 1. but get mentioned in current issue/comment.
3030
func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []int64) error {
3131

@@ -69,11 +69,13 @@ func mailIssueCommentToParticipants(ctx *mailCommentContext, mentions []int64) e
6969

7070
// =========== Repo watchers ===========
7171
// Make repo watchers last, since it's likely the list with the most users
72-
ids, err = models.GetRepoWatchersIDs(ctx.Issue.RepoID)
73-
if err != nil {
74-
return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err)
72+
if !(ctx.Issue.IsPull && ctx.Issue.PullRequest.IsWorkInProgress()) {
73+
ids, err = models.GetRepoWatchersIDs(ctx.Issue.RepoID)
74+
if err != nil {
75+
return fmt.Errorf("GetRepoWatchersIDs(%d): %v", ctx.Issue.RepoID, err)
76+
}
77+
unfiltered = append(ids, unfiltered...)
7578
}
76-
unfiltered = append(ids, unfiltered...)
7779

7880
visited := make(map[int64]bool, len(unfiltered)+len(mentions)+1)
7981

0 commit comments

Comments
 (0)