mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-08 18:04:14 +01:00
API: don't allow merged PRs to be reopened (#17192)
* api: dont open merged PRs * don't change base branch when already merged * don't allow any state change * also validate opening merged PRs in EditIssue Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
parent
8f75a559ee
commit
1f45b3a629
2 changed files with 14 additions and 1 deletions
|
@ -790,6 +790,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)
|
||||
|
|
|
@ -564,6 +564,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)
|
||||
|
@ -585,7 +589,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
|
||||
|
|
Loading…
Reference in a new issue