@@ -66,6 +66,23 @@ func (err ErrNotValidReviewRequest) Unwrap() error {
6666 return util .ErrInvalidArgument
6767}
6868
69+ // ErrReviewRequestOnClosedPR represents an error when an user tries to request a re-review on a closed or merged PR.
70+ type ErrReviewRequestOnClosedPR struct {}
71+
72+ // IsErrReviewRequestOnClosedPR checks if an error is an ErrReviewRequestOnClosedPR.
73+ func IsErrReviewRequestOnClosedPR (err error ) bool {
74+ _ , ok := err .(ErrReviewRequestOnClosedPR )
75+ return ok
76+ }
77+
78+ func (err ErrReviewRequestOnClosedPR ) Error () string {
79+ return "cannot request a re-review on a merged PR"
80+ }
81+
82+ func (err ErrReviewRequestOnClosedPR ) Unwrap () error {
83+ return util .ErrPermissionDenied
84+ }
85+
6986// ReviewType defines the sort of feedback a review gives
7087type ReviewType int
7188
@@ -618,9 +635,33 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
618635 return nil , err
619636 }
620637
621- // skip it when reviewer hase been request to review
622- if review != nil && review .Type == ReviewTypeRequest {
623- return nil , committer .Commit () // still commit the transaction, or committer.Close() will rollback it, even if it's a reused transaction.
638+ if review != nil {
639+ // NOTE: in case of failure we still commit the transaction here, else committer.Close() will rollback it,
640+ // even if it's a reused transaction.
641+
642+ // skip it when reviewer hase been request to review
643+ if review .Type == ReviewTypeRequest {
644+ return nil , committer .Commit ()
645+ }
646+
647+ if issue .IsClosed {
648+ var err error = ErrReviewRequestOnClosedPR {}
649+ if err2 := committer .Commit (); err2 != nil {
650+ err = err2
651+ }
652+ return nil , err
653+ }
654+
655+ if err := issue .LoadPullRequest (ctx ); err != nil {
656+ return nil , err
657+ }
658+ if issue .PullRequest .HasMerged {
659+ var err error = ErrReviewRequestOnClosedPR {}
660+ if err2 := committer .Commit (); err2 != nil {
661+ err = err2
662+ }
663+ return nil , err
664+ }
624665 }
625666
626667 // if the reviewer is an official reviewer,
0 commit comments