1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2025-08-05 09:55:20 +02:00

fix: cancel a review (#7454)

- Fixes #7152
- If a review no longer has any pending comments, remove that review from the database.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7454
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Leni Kadali <lenikadali@noreply.codeberg.org>
Co-committed-by: Leni Kadali <lenikadali@noreply.codeberg.org>
This commit is contained in:
Leni Kadali 2025-05-08 11:21:00 +00:00 committed by Gusted
parent 4183fa9a03
commit f4af3191ef
2 changed files with 25 additions and 1 deletions

View file

@ -119,7 +119,28 @@ func UpdateComment(ctx context.Context, c *issues_model.Comment, contentVersion
// DeleteComment deletes the comment
func DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) error {
err := db.WithTx(ctx, func(ctx context.Context) error {
return issues_model.DeleteComment(ctx, comment)
reviewID := comment.ReviewID
err := issues_model.DeleteComment(ctx, comment)
if err != nil {
return err
}
if comment.Review != nil {
reviewType := comment.Review.Type
if reviewType == issues_model.ReviewTypePending {
found, err := db.GetEngine(ctx).Table("comment").Where("review_id = ?", reviewID).Exist()
if err != nil {
return err
} else if !found {
_, err := db.GetEngine(ctx).Table("review").Where("id = ?", reviewID).Delete()
if err != nil {
return err
}
}
}
}
return nil
})
if err != nil {
return err