mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-17 11:59:30 +00:00
Add option to API to update PullRequest base branch (#11666)
* EditPull: add option to change base Close #11552
This commit is contained in:
parent
880ae454db
commit
5814079bf5
4 changed files with 52 additions and 3 deletions
|
@ -464,6 +464,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":
|
||||
|
@ -590,6 +592,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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue