@@ -742,17 +742,9 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
742
742
if err != nil {
743
743
return nil , err
744
744
} else if official {
745
- // recalculate the latest official review for reviewer
746
- review , err := GetReviewByIssueIDAndUserID (ctx , issue .ID , reviewer .ID )
747
- if err != nil && ! IsErrReviewNotExist (err ) {
745
+ if err := restoreLatestOfficialReview (ctx , issue .ID , reviewer .ID ); err != nil {
748
746
return nil , err
749
747
}
750
-
751
- if review != nil {
752
- if _ , err := db .Exec (ctx , "UPDATE `review` SET official=? WHERE id=?" , true , review .ID ); err != nil {
753
- return nil , err
754
- }
755
- }
756
748
}
757
749
758
750
comment , err := CreateCommentCtx (ctx , & CreateCommentOptions {
@@ -770,6 +762,22 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
770
762
return comment , committer .Commit ()
771
763
}
772
764
765
+ // Recalculate the latest official review for reviewer
766
+ func restoreLatestOfficialReview (ctx context.Context , issueID , reviewerID int64 ) error {
767
+ review , err := GetReviewByIssueIDAndUserID (ctx , issueID , reviewerID )
768
+ if err != nil && ! IsErrReviewNotExist (err ) {
769
+ return err
770
+ }
771
+
772
+ if review != nil {
773
+ if _ , err := db .Exec (ctx , "UPDATE `review` SET official=? WHERE id=?" , true , review .ID ); err != nil {
774
+ return err
775
+ }
776
+ }
777
+
778
+ return nil
779
+ }
780
+
773
781
// AddTeamReviewRequest add a review request from one team
774
782
func AddTeamReviewRequest (issue * Issue , reviewer * organization.Team , doer * user_model.User ) (* Comment , error ) {
775
783
ctx , committer , err := db .TxContext ()
@@ -988,6 +996,12 @@ func DeleteReview(r *Review) error {
988
996
return err
989
997
}
990
998
999
+ if r .Official {
1000
+ if err := restoreLatestOfficialReview (ctx , r .IssueID , r .ReviewerID ); err != nil {
1001
+ return err
1002
+ }
1003
+ }
1004
+
991
1005
return committer .Commit ()
992
1006
}
993
1007
0 commit comments