Prevent allow/reject reviews on merged/closed PRs (#30686)

Resolves #30675.
This commit is contained in:
Kemal Zebari 2024-04-27 04:55:03 -07:00 committed by GitHub
parent 238eb3ff9f
commit dd301cae1c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 119 additions and 14 deletions

View file

@ -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