Skip to content

Commit

Permalink
API: don't allow merged PRs to be reopened (#17271)
Browse files Browse the repository at this point in the history
  • Loading branch information
noerw authored Oct 8, 2021
1 parent 245596e commit c927ebd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,15 @@ func EditIssue(ctx *context.APIContext) {
}
}
if form.State != nil {
if issue.IsPull {
if pr, err := issue.GetPullRequest(); err != nil {
ctx.Error(http.StatusInternalServerError, "GetPullRequest", err)
return
} else if pr.HasMerged {
ctx.Error(http.StatusPreconditionFailed, "MergedPRState", "cannot change state of this pull request, it was already merged")
return
}
}
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
Expand Down
6 changes: 5 additions & 1 deletion routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,10 @@ func EditPullRequest(ctx *context.APIContext) {
}

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

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

0 comments on commit c927ebd

Please sign in to comment.