@@ -733,17 +733,9 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
733
733
if err != nil {
734
734
return nil , err
735
735
} else if official {
736
- // recalculate the latest official review for reviewer
737
- review , err := GetReviewByIssueIDAndUserID (ctx , issue .ID , reviewer .ID )
738
- if err != nil && ! IsErrReviewNotExist (err ) {
736
+ if err := restoreLatestOfficialReview (ctx , issue .ID , reviewer .ID ); err != nil {
739
737
return nil , err
740
738
}
741
-
742
- if review != nil {
743
- if _ , err := db .Exec (ctx , "UPDATE `review` SET official=? WHERE id=?" , true , review .ID ); err != nil {
744
- return nil , err
745
- }
746
- }
747
739
}
748
740
749
741
comment , err := CreateComment (ctx , & CreateCommentOptions {
@@ -761,6 +753,22 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
761
753
return comment , committer .Commit ()
762
754
}
763
755
756
+ // Recalculate the latest official review for reviewer
757
+ func restoreLatestOfficialReview (ctx context.Context , issueID , reviewerID int64 ) error {
758
+ review , err := GetReviewByIssueIDAndUserID (ctx , issueID , reviewerID )
759
+ if err != nil && ! IsErrReviewNotExist (err ) {
760
+ return err
761
+ }
762
+
763
+ if review != nil {
764
+ if _ , err := db .Exec (ctx , "UPDATE `review` SET official=? WHERE id=?" , true , review .ID ); err != nil {
765
+ return err
766
+ }
767
+ }
768
+
769
+ return nil
770
+ }
771
+
764
772
// AddTeamReviewRequest add a review request from one team
765
773
func AddTeamReviewRequest (issue * Issue , reviewer * organization.Team , doer * user_model.User ) (* Comment , error ) {
766
774
ctx , committer , err := db .TxContext (db .DefaultContext )
@@ -979,6 +987,12 @@ func DeleteReview(r *Review) error {
979
987
return err
980
988
}
981
989
990
+ if r .Official {
991
+ if err := restoreLatestOfficialReview (ctx , r .IssueID , r .ReviewerID ); err != nil {
992
+ return err
993
+ }
994
+ }
995
+
982
996
return committer .Commit ()
983
997
}
984
998
0 commit comments