aboutsummaryrefslogtreecommitdiffstats
path: root/models/issues/review.go
diff options
context:
space:
mode:
authorJimmy Praet <jimmy.praet@telenet.be>2023-01-15 06:00:09 +0100
committerGitHub <noreply@github.com>2023-01-15 07:00:09 +0200
commitfe519d86338761b91ff1702b70008895ef89f7eb (patch)
treed9f80800e46eedf3797f4498538fc5ced62ce8e9 /models/issues/review.go
parentfc037b4b825f0501a1489e10d7c822435d825cb7 (diff)
downloadgitea-fe519d86338761b91ff1702b70008895ef89f7eb.tar.gz
gitea-fe519d86338761b91ff1702b70008895ef89f7eb.zip
Restore previous official review when an official review is deleted (#22449)
Fix #22406 Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'models/issues/review.go')
-rw-r--r--models/issues/review.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/models/issues/review.go b/models/issues/review.go
index 7dee28fe97..ae4029e80f 100644
--- a/models/issues/review.go
+++ b/models/issues/review.go
@@ -733,17 +733,9 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
if err != nil {
return nil, err
} else if official {
- // recalculate the latest official review for reviewer
- review, err := GetReviewByIssueIDAndUserID(ctx, issue.ID, reviewer.ID)
- if err != nil && !IsErrReviewNotExist(err) {
+ if err := restoreLatestOfficialReview(ctx, issue.ID, reviewer.ID); err != nil {
return nil, err
}
-
- if review != nil {
- if _, err := db.Exec(ctx, "UPDATE `review` SET official=? WHERE id=?", true, review.ID); err != nil {
- return nil, err
- }
- }
}
comment, err := CreateComment(ctx, &CreateCommentOptions{
@@ -761,6 +753,22 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
return comment, committer.Commit()
}
+// Recalculate the latest official review for reviewer
+func restoreLatestOfficialReview(ctx context.Context, issueID, reviewerID int64) error {
+ review, err := GetReviewByIssueIDAndUserID(ctx, issueID, reviewerID)
+ if err != nil && !IsErrReviewNotExist(err) {
+ return err
+ }
+
+ if review != nil {
+ if _, err := db.Exec(ctx, "UPDATE `review` SET official=? WHERE id=?", true, review.ID); err != nil {
+ return err
+ }
+ }
+
+ return nil
+}
+
// AddTeamReviewRequest add a review request from one team
func AddTeamReviewRequest(issue *Issue, reviewer *organization.Team, doer *user_model.User) (*Comment, error) {
ctx, committer, err := db.TxContext(db.DefaultContext)
@@ -979,6 +987,12 @@ func DeleteReview(r *Review) error {
return err
}
+ if r.Official {
+ if err := restoreLatestOfficialReview(ctx, r.IssueID, r.ReviewerID); err != nil {
+ return err
+ }
+ }
+
return committer.Commit()
}