[BUG] Don't fire notification for comment of pending review

- When a comment was updated or deleted and was part of an
pending/ongoing review, it would have triggered a notification, such as
a webhook.
- This patch checks if the comment is part of a pending review and then
does not fire a notification and, in the case of updating a comment,
does not save the content history because this is not necessary if it is
still a "draft" comment given it is a pending comment (there is no need
to see my embarrassing typos).
- Adds integration tests.
- Resolves https://codeberg.org/forgejo/forgejo/issues/4368
This commit is contained in:
Gusted 2024-07-14 07:38:45 +02:00
parent adf4dcdbbf
commit 15c64122a6
No known key found for this signature in database
GPG key ID: FD821B732837125F
5 changed files with 173 additions and 4 deletions

View file

@ -75,7 +75,12 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m
// UpdateComment updates information of comment.
func UpdateComment(ctx context.Context, c *issues_model.Comment, contentVersion int, doer *user_model.User, oldContent string) error {
needsContentHistory := c.Content != oldContent && c.Type.HasContentSupport()
if err := c.LoadReview(ctx); err != nil {
return err
}
isPartOfPendingReview := c.Review != nil && c.Review.Type == issues_model.ReviewTypePending
needsContentHistory := c.Content != oldContent && c.Type.HasContentSupport() && !isPartOfPendingReview
if needsContentHistory {
hasContentHistory, err := issues_model.HasIssueContentHistory(ctx, c.IssueID, c.ID)
if err != nil {
@ -104,7 +109,9 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, contentVersion
}
}
notify_service.UpdateComment(ctx, doer, c, oldContent)
if !isPartOfPendingReview {
notify_service.UpdateComment(ctx, doer, c, oldContent)
}
return nil
}
@ -118,7 +125,12 @@ func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_m
return err
}
notify_service.DeleteComment(ctx, doer, comment)
if err := comment.LoadReview(ctx); err != nil {
return err
}
if comment.Review == nil || comment.Review.Type != issues_model.ReviewTypePending {
notify_service.DeleteComment(ctx, doer, comment)
}
return nil
}