Skip to content

Commit 8cbec63

Browse files
lunnywxiaoguang
andauthored
Don't send trigger for a pending review's comment create/update/delete (#34928)
Fix #18846 Fix #34924 --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 6455c82 commit 8cbec63

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

models/issues/comment.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,8 @@ func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository
715715
return nil
716716
}
717717

718-
func (c *Comment) loadReview(ctx context.Context) (err error) {
718+
// LoadReview loads the associated review
719+
func (c *Comment) LoadReview(ctx context.Context) (err error) {
719720
if c.ReviewID == 0 {
720721
return nil
721722
}
@@ -732,11 +733,6 @@ func (c *Comment) loadReview(ctx context.Context) (err error) {
732733
return nil
733734
}
734735

735-
// LoadReview loads the associated review
736-
func (c *Comment) LoadReview(ctx context.Context) error {
737-
return c.loadReview(ctx)
738-
}
739-
740736
// DiffSide returns "previous" if Comment.Line is a LOC of the previous changes and "proposed" if it is a LOC of the proposed changes.
741737
func (c *Comment) DiffSide() string {
742738
if c.Line < 0 {
@@ -856,7 +852,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
856852
}
857853
if comment.ReviewID != 0 {
858854
if comment.Review == nil {
859-
if err := comment.loadReview(ctx); err != nil {
855+
if err := comment.LoadReview(ctx); err != nil {
860856
return err
861857
}
862858
}

services/notify/notify.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,25 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
4646
}
4747
}
4848

49+
func shouldSendCommentChangeNotification(ctx context.Context, comment *issues_model.Comment) bool {
50+
if err := comment.LoadReview(ctx); err != nil {
51+
log.Error("LoadReview: %v", err)
52+
return false
53+
} else if comment.Review != nil && comment.Review.Type == issues_model.ReviewTypePending {
54+
// Pending review comments updating should not triggered
55+
return false
56+
}
57+
return true
58+
}
59+
4960
// CreateIssueComment notifies issue comment related message to notifiers
5061
func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_model.Repository,
5162
issue *issues_model.Issue, comment *issues_model.Comment, mentions []*user_model.User,
5263
) {
64+
if !shouldSendCommentChangeNotification(ctx, comment) {
65+
return
66+
}
67+
5368
for _, notifier := range notifiers {
5469
notifier.CreateIssueComment(ctx, doer, repo, issue, comment, mentions)
5570
}
@@ -156,13 +171,21 @@ func PullReviewDismiss(ctx context.Context, doer *user_model.User, review *issue
156171

157172
// UpdateComment notifies update comment to notifiers
158173
func UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
174+
if !shouldSendCommentChangeNotification(ctx, c) {
175+
return
176+
}
177+
159178
for _, notifier := range notifiers {
160179
notifier.UpdateComment(ctx, doer, c, oldContent)
161180
}
162181
}
163182

164183
// DeleteComment notifies delete comment to notifiers
165184
func DeleteComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment) {
185+
if !shouldSendCommentChangeNotification(ctx, c) {
186+
return
187+
}
188+
166189
for _, notifier := range notifiers {
167190
notifier.DeleteComment(ctx, doer, c)
168191
}

0 commit comments

Comments
 (0)