Skip to content

Commit 9adf175

Browse files
GiteaBotlunnywxiaoguang
authored
Don't send trigger for a pending review's comment create/update/delete (go-gitea#34928) (go-gitea#34939)
Backport go-gitea#34928 by lunny Fix go-gitea#18846 Fix go-gitea#34924 Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent c3fa2a8 commit 9adf175

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
@@ -719,7 +719,8 @@ func (c *Comment) LoadReactions(ctx context.Context, repo *repo_model.Repository
719719
return nil
720720
}
721721

722-
func (c *Comment) loadReview(ctx context.Context) (err error) {
722+
// LoadReview loads the associated review
723+
func (c *Comment) LoadReview(ctx context.Context) (err error) {
723724
if c.ReviewID == 0 {
724725
return nil
725726
}
@@ -736,11 +737,6 @@ func (c *Comment) loadReview(ctx context.Context) (err error) {
736737
return nil
737738
}
738739

739-
// LoadReview loads the associated review
740-
func (c *Comment) LoadReview(ctx context.Context) error {
741-
return c.loadReview(ctx)
742-
}
743-
744740
// DiffSide returns "previous" if Comment.Line is a LOC of the previous changes and "proposed" if it is a LOC of the proposed changes.
745741
func (c *Comment) DiffSide() string {
746742
if c.Line < 0 {
@@ -860,7 +856,7 @@ func updateCommentInfos(ctx context.Context, opts *CreateCommentOptions, comment
860856
}
861857
if comment.ReviewID != 0 {
862858
if comment.Review == nil {
863-
if err := comment.loadReview(ctx); err != nil {
859+
if err := comment.LoadReview(ctx); err != nil {
864860
return err
865861
}
866862
}

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)