diff options
author | 6543 <6543@obermui.de> | 2020-06-07 22:20:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-07 23:20:53 +0300 |
commit | 78f0b5b92bd8739d6851fe00a12fdffda5f6e0dd (patch) | |
tree | 929a9a83a76297760cb8db714d0c7e991d53eaa8 /routers | |
parent | 20951c5c215bb76385eb70e256e6858c1d53aa05 (diff) | |
download | gitea-78f0b5b92bd8739d6851fe00a12fdffda5f6e0dd.tar.gz gitea-78f0b5b92bd8739d6851fe00a12fdffda5f6e0dd.zip |
Add option to API to update PullRequest base branch (#11666) (#11796)
* EditPull: add option to change base
Close #11552
Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/pull.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index bddf4e48f7..8425aa6129 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -382,6 +382,8 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { // "$ref": "#/responses/PullRequest" // "403": // "$ref": "#/responses/forbidden" + // "409": + // "$ref": "#/responses/error" // "412": // "$ref": "#/responses/error" // "422": @@ -508,6 +510,30 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed) } + // change pull target branch + if 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 + } + if err := pull_service.ChangeTargetBranch(pr, ctx.User, form.Base); err != nil { + if models.IsErrPullRequestAlreadyExists(err) { + ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err) + return + } else if models.IsErrIssueIsClosed(err) { + ctx.Error(http.StatusUnprocessableEntity, "IsErrIssueIsClosed", err) + return + } else if models.IsErrPullRequestHasMerged(err) { + ctx.Error(http.StatusConflict, "IsErrPullRequestHasMerged", err) + return + } else { + ctx.InternalServerError(err) + } + return + } + notification.NotifyPullRequestChangeTargetBranch(ctx.User, pr, form.Base) + } + // Refetch from database pr, err = models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pr.Index) if err != nil { |