@@ -733,17 +733,9 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
733733 if err != nil {
734734 return nil , err
735735 } 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 {
739737 return nil , err
740738 }
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- }
747739 }
748740
749741 comment , err := CreateComment (ctx , & CreateCommentOptions {
@@ -761,6 +753,22 @@ func RemoveReviewRequest(issue *Issue, reviewer, doer *user_model.User) (*Commen
761753 return comment , committer .Commit ()
762754}
763755
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+
764772// AddTeamReviewRequest add a review request from one team
765773func AddTeamReviewRequest (issue * Issue , reviewer * organization.Team , doer * user_model.User ) (* Comment , error ) {
766774 ctx , committer , err := db .TxContext (db .DefaultContext )
@@ -979,6 +987,12 @@ func DeleteReview(r *Review) error {
979987 return err
980988 }
981989
990+ if r .Official {
991+ if err := restoreLatestOfficialReview (ctx , r .IssueID , r .ReviewerID ); err != nil {
992+ return err
993+ }
994+ }
995+
982996 return committer .Commit ()
983997}
984998
0 commit comments