Skip to content

Commit c927ebd

Browse files
authored
API: don't allow merged PRs to be reopened (#17271)
1 parent 245596e commit c927ebd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

routers/api/v1/repo/issue.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,15 @@ func EditIssue(ctx *context.APIContext) {
752752
}
753753
}
754754
if form.State != nil {
755+
if issue.IsPull {
756+
if pr, err := issue.GetPullRequest(); err != nil {
757+
ctx.Error(http.StatusInternalServerError, "GetPullRequest", err)
758+
return
759+
} else if pr.HasMerged {
760+
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
761+
return
762+
}
763+
}
755764
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
756765
}
757766
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)

routers/api/v1/repo/pull.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,10 @@ func EditPullRequest(ctx *context.APIContext) {
584584
}
585585

586586
if form.State != nil {
587+
if pr.HasMerged {
588+
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
589+
return
590+
}
587591
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
588592
}
589593
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
@@ -605,7 +609,7 @@ func EditPullRequest(ctx *context.APIContext) {
605609
}
606610

607611
// change pull target branch
608-
if len(form.Base) != 0 && form.Base != pr.BaseBranch {
612+
if !pr.HasMerged && len(form.Base) != 0 && form.Base != pr.BaseBranch {
609613
if !ctx.Repo.GitRepo.IsBranchExist(form.Base) {
610614
ctx.Error(http.StatusNotFound, "NewBaseBranchNotExist", fmt.Errorf("new base '%s' not exist", form.Base))
611615
return

0 commit comments

Comments
 (0)