Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to API to update PullRequest base branch #11666

Merged
merged 21 commits into from
Jun 7, 2020
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0fc233b
EditPull: add option to change base
6543 May 29, 2020
4ce24ee
Add/Extend Test
6543 May 29, 2020
299b9a5
Merge branch 'master' into api-pull_change-base_11552
6543 May 29, 2020
072d1c8
Merge branch 'master' into api-pull_change-base_11552
6543 May 29, 2020
f4fa454
Merge branch 'master' into api-pull_change-base_11552
6543 May 29, 2020
1c7e667
Merge branch 'master' into api-pull_change-base_11552
6543 May 30, 2020
0769fe9
Merge branch 'master' into api-pull_change-base_11552
6543 May 30, 2020
1ecad15
Merge branch 'master' into api-pull_change-base_11552
6543 May 30, 2020
4a9440d
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 2, 2020
88e2b7a
CI.restart()
6543 Jun 2, 2020
653f7d4
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 3, 2020
ed86bd9
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 3, 2020
fcb89ec
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 3, 2020
381a8b8
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 3, 2020
883ad9c
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 3, 2020
44bb2f0
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 4, 2020
c01569d
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 5, 2020
fa9ec12
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 5, 2020
6c0a2c5
Merge branch 'master' into api-pull_change-base_11552
zeripath Jun 6, 2020
b86da5e
Merge branch 'master' into api-pull_change-base_11552
6543 Jun 7, 2020
cd1a4c1
Merge branch 'master' into api-pull_change-base_11552
zeripath Jun 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions integrations/api_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestAPIMergePullWIP(t *testing.T) {
session.MakeRequest(t, req, http.StatusMethodNotAllowed)
}

func TestAPICreatePullSuccess1(t *testing.T) {
func TestAPICreatePullSuccess(t *testing.T) {
defer prepareTestEnv(t)()
repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
// repo10 have code, pulls units.
Expand All @@ -78,7 +78,7 @@ func TestAPICreatePullSuccess1(t *testing.T) {
session.MakeRequest(t, req, 201)
}

func TestAPICreatePullSuccess2(t *testing.T) {
func TestAPIEditPull(t *testing.T) {
defer prepareTestEnv(t)()
repo10 := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 10}).(*models.Repository)
owner10 := models.AssertExistsAndLoadBean(t, &models.User{ID: repo10.OwnerID}).(*models.User)
Expand All @@ -90,6 +90,21 @@ func TestAPICreatePullSuccess2(t *testing.T) {
Base: "master",
Title: "create a success pr",
})
pull := new(api.PullRequest)
resp := session.MakeRequest(t, req, 201)
DecodeJSON(t, resp, pull)
assert.EqualValues(t, "master", pull.Base.Name)

req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s", owner10.Name, repo10.Name, pull.Index, token), &api.EditPullRequestOption{
Base: "feature/1",
Title: "edit a this pr",
})
resp = session.MakeRequest(t, req, 201)
DecodeJSON(t, resp, pull)
assert.EqualValues(t, "feature/1", pull.Base.Name)

session.MakeRequest(t, req, 201)
req = NewRequestWithJSON(t, http.MethodPatch, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d?token=%s", owner10.Name, repo10.Name, pull.Index, token), &api.EditPullRequestOption{
Base: "not-exist",
})
session.MakeRequest(t, req, 404)
}
1 change: 1 addition & 0 deletions modules/structs/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type CreatePullRequestOption struct {
type EditPullRequestOption struct {
Title string `json:"title"`
Body string `json:"body"`
Base string `json:"base"`
Assignee string `json:"assignee"`
Assignees []string `json:"assignees"`
Milestone int64 `json:"milestone"`
Expand Down
26 changes: 26 additions & 0 deletions routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6640,6 +6640,9 @@
"403": {
"$ref": "#/responses/forbidden"
},
"409": {
"$ref": "#/responses/error"
},
"412": {
"$ref": "#/responses/error"
},
Expand Down Expand Up @@ -12151,6 +12154,10 @@
},
"x-go-name": "Assignees"
},
"base": {
"type": "string",
"x-go-name": "Base"
},
"body": {
"type": "string",
"x-go-name": "Body"
Expand Down