@@ -742,17 +742,9 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
742742 if err != nil {
743743 return nil , err
744744 } 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 {
748746 return nil , err
749747 }
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- }
756748 }
757749
758750 comment , err := CreateCommentCtx (ctx , & CreateCommentOptions {
@@ -770,6 +762,22 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
770762 return comment , committer .Commit ()
771763}
772764
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+
773781// AddTeamReviewRequest add a review request from one team
774782func AddTeamReviewRequest (issue * Issue , reviewer * organization.Team , doer * user_model.User ) (* Comment , error ) {
775783 ctx , committer , err := db .TxContext ()
@@ -988,6 +996,12 @@ func DeleteReview(r *Review) error {
988996 return err
989997 }
990998
999+ if r .Official {
1000+ if err := restoreLatestOfficialReview (ctx , r .IssueID , r .ReviewerID ); err != nil {
1001+ return err
1002+ }
1003+ }
1004+
9911005 return committer .Commit ()
9921006}
9931007
0 commit comments