Skip to content

Commit 0fc233b

Browse files
committed
EditPull: add option to change base
1 parent ab73b56 commit 0fc233b

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

modules/structs/pull.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type CreatePullRequestOption struct {
8282
type EditPullRequestOption struct {
8383
Title string `json:"title"`
8484
Body string `json:"body"`
85+
Base string `json:"base"`
8586
Assignee string `json:"assignee"`
8687
Assignees []string `json:"assignees"`
8788
Milestone int64 `json:"milestone"`

routers/api/v1/repo/pull.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
382382
// "$ref": "#/responses/PullRequest"
383383
// "403":
384384
// "$ref": "#/responses/forbidden"
385+
// "409":
386+
// "$ref": "#/responses/error"
385387
// "412":
386388
// "$ref": "#/responses/error"
387389
// "422":
@@ -508,6 +510,30 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) {
508510
notification.NotifyIssueChangeStatus(ctx.User, issue, statusChangeComment, issue.IsClosed)
509511
}
510512

513+
// change pull target branch
514+
if len(form.Base) != 0 && form.Base != pr.BaseBranch {
515+
if !ctx.Repo.GitRepo.IsBranchExist(form.Base) {
516+
ctx.Error(http.StatusNotFound, "NewBaseBranchNotExist", fmt.Errorf("new base '%s' not exist", form.Base))
517+
return
518+
}
519+
if err := pull_service.ChangeTargetBranch(pr, ctx.User, form.Base); err != nil {
520+
if models.IsErrPullRequestAlreadyExists(err) {
521+
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
522+
return
523+
} else if models.IsErrIssueIsClosed(err) {
524+
ctx.Error(http.StatusUnprocessableEntity, "IsErrPullRequestAlreadyExists", err)
525+
return
526+
} else if models.IsErrPullRequestHasMerged(err) {
527+
ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
528+
return
529+
} else {
530+
ctx.InternalServerError(err)
531+
}
532+
return
533+
}
534+
notification.NotifyPullRequestChangeTargetBranch(ctx.User, pr, form.Base)
535+
}
536+
511537
// Refetch from database
512538
pr, err = models.GetPullRequestByIndex(ctx.Repo.Repository.ID, pr.Index)
513539
if err != nil {

templates/swagger/v1_json.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6575,6 +6575,9 @@
65756575
"403": {
65766576
"$ref": "#/responses/forbidden"
65776577
},
6578+
"409": {
6579+
"$ref": "#/responses/error"
6580+
},
65786581
"412": {
65796582
"$ref": "#/responses/error"
65806583
},
@@ -11959,6 +11962,10 @@
1195911962
},
1196011963
"x-go-name": "Assignees"
1196111964
},
11965+
"base": {
11966+
"type": "string",
11967+
"x-go-name": "Base"
11968+
},
1196211969
"body": {
1196311970
"type": "string",
1196411971
"x-go-name": "Body"

0 commit comments

Comments
 (0)