diff options
author | Norwin <noerw@users.noreply.github.com> | 2021-10-03 05:11:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-02 23:11:17 -0400 |
commit | 1f45b3a629c0799359faa7d4e892522a191c9682 (patch) | |
tree | f75957a70d0475352b55176719cf5ffb05e12715 /routers | |
parent | 8f75a559eedd2ebc8790c4b361595bd9c1363a48 (diff) | |
download | gitea-1f45b3a629c0799359faa7d4e892522a191c9682.tar.gz gitea-1f45b3a629c0799359faa7d4e892522a191c9682.zip |
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>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue.go | 9 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 6 |
2 files changed, 14 insertions, 1 deletions
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 7b97a5683a..17a3becd5b 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -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) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 3974069ab4..6718224d7d 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -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 |