summaryrefslogtreecommitdiffstats
path: root/services/pull
diff options
context:
space:
mode:
authorKemal Zebari <60799661+kemzeb@users.noreply.github.com>2024-04-27 04:55:03 -0700
committerGitHub <noreply@github.com>2024-04-27 11:55:03 +0000
commitdd301cae1c40c9ef2805bd13af6b09a81ff4f5d7 (patch)
tree9ce20393f8f1ee28493aa52400b0b68cc4cd439c /services/pull
parent238eb3ff9f36bcf7b4637957ae2dd98446105894 (diff)
downloadgitea-dd301cae1c40c9ef2805bd13af6b09a81ff4f5d7.tar.gz
gitea-dd301cae1c40c9ef2805bd13af6b09a81ff4f5d7.zip
Prevent allow/reject reviews on merged/closed PRs (#30686)
Resolves #30675.
Diffstat (limited to 'services/pull')
-rw-r--r--services/pull/review.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/services/pull/review.go b/services/pull/review.go
index 5bf1991d13..e303cd9a9d 100644
--- a/services/pull/review.go
+++ b/services/pull/review.go
@@ -6,6 +6,7 @@ package pull
import (
"context"
+ "errors"
"fmt"
"io"
"regexp"
@@ -43,6 +44,9 @@ func (err ErrDismissRequestOnClosedPR) Unwrap() error {
return util.ErrPermissionDenied
}
+// ErrSubmitReviewOnClosedPR represents an error when an user tries to submit an approve or reject review associated to a closed or merged PR.
+var ErrSubmitReviewOnClosedPR = errors.New("can't submit review for a closed or merged PR")
+
// checkInvalidation checks if the line of code comment got changed by another commit.
// If the line got changed the comment is going to be invalidated.
func checkInvalidation(ctx context.Context, c *issues_model.Comment, doer *user_model.User, repo *git.Repository, branch string) error {
@@ -293,6 +297,10 @@ func SubmitReview(ctx context.Context, doer *user_model.User, gitRepo *git.Repos
if reviewType != issues_model.ReviewTypeApprove && reviewType != issues_model.ReviewTypeReject {
stale = false
} else {
+ if issue.IsClosed {
+ return nil, nil, ErrSubmitReviewOnClosedPR
+ }
+
headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
if err != nil {
return nil, nil, err