@@ -66,6 +66,23 @@ func (err ErrNotValidReviewRequest) Unwrap() error {
66
66
return util .ErrInvalidArgument
67
67
}
68
68
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
+
69
86
// ReviewType defines the sort of feedback a review gives
70
87
type ReviewType int
71
88
@@ -618,9 +635,33 @@ func AddReviewRequest(ctx context.Context, issue *Issue, reviewer, doer *user_mo
618
635
return nil , err
619
636
}
620
637
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
+ }
624
665
}
625
666
626
667
// if the reviewer is an official reviewer,
0 commit comments