Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
8b5c16e4
Commit
8b5c16e4
authored
Nov 28, 2016
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Ability to remove source branch
parent
bd674591
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
26 deletions
+47
-26
changelogs/unreleased/api-remove-source-branch.yml
changelogs/unreleased/api-remove-source-branch.yml
+4
-0
doc/api/merge_requests.md
doc/api/merge_requests.md
+26
-23
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+6
-2
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+11
-1
No files found.
changelogs/unreleased/api-remove-source-branch.yml
0 → 100644
View file @
8b5c16e4
---
title
:
'
API:
Ability
to
set
'
'
should_remove_source_branch'
'
on
merge
requests'
merge_request
:
author
:
Robert Schilling
doc/api/merge_requests.md
View file @
8b5c16e4
...
@@ -271,17 +271,18 @@ Creates a new merge request.
...
@@ -271,17 +271,18 @@ Creates a new merge request.
POST /projects/:id/merge_requests
POST /projects/:id/merge_requests
```
```
Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
-
`id`
(required) - The ID of a project
|
`id`
| string | yes | The ID of a project |
-
`source_branch`
(required) - The source branch
|
`source_branch`
| string | yes | The source branch |
-
`target_branch`
(required) - The target branch
|
`target_branch`
| string | yes | The target branch |
-
`assignee_id`
(optional) - Assignee user ID
|
`title`
| string | yes | Title of MR |
-
`title`
(required) - Title of MR
|
`assignee_id`
| integer | no | Assignee user ID |
-
`description`
(optional) - Description of MR
|
`description`
| string | no | Description of MR |
-
`target_project_id`
(optional) - The target project (numeric id)
|
`target_project_id`
| integer | no | The target project (numeric id) |
-
`labels`
(optional) - Labels for MR as a comma-separated list
|
`labels`
| string | no | Labels for MR as a comma-separated list |
-
`milestone_id`
(optional) - Milestone ID
|
`milestone_id`
| integer | no | The ID of a milestone |
|
`remove_source_branch`
| boolean | no | Flag indicating if a merge request should remove the source branch when merging |
```
json
```
json
{
{
...
@@ -346,17 +347,19 @@ Updates an existing merge request. You can change the target branch, title, or e
...
@@ -346,17 +347,19 @@ Updates an existing merge request. You can change the target branch, title, or e
PUT /projects/:id/merge_requests/:merge_request_id
PUT /projects/:id/merge_requests/:merge_request_id
```
```
Parameters:
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
-
`id`
(required) - The ID of a project
|
`id`
| string | yes | The ID of a project |
-
`merge_request_id`
(required) - ID of MR
|
`merge_request_id`
| integer | yes | The ID of a merge request |
-
`target_branch`
- The target branch
|
`source_branch`
| string | yes | The source branch |
-
`assignee_id`
- Assignee user ID
|
`target_branch`
| string | yes | The target branch |
-
`title`
- Title of MR
|
`title`
| string | yes | Title of MR |
-
`description`
- Description of MR
|
`assignee_id`
| integer | no | Assignee user ID |
-
`state_event`
- New state (close|reopen|merge)
|
`description`
| string | no | Description of MR |
-
`labels`
(optional) - Labels for MR as a comma-separated list
|
`target_project_id`
| integer | no | The target project (numeric id) |
-
`milestone_id`
(optional) - Milestone ID
|
`labels`
| string | no | Labels for MR as a comma-separated list |
|
`milestone_id`
| integer | no | The ID of a milestone |
|
`remove_source_branch`
| boolean | no | Flag indicating if a merge request should remove the source branch when merging |
```
json
```
json
{
{
...
@@ -807,7 +810,7 @@ Example response:
...
@@ -807,7 +810,7 @@ Example response:
## Create a todo
## Create a todo
Manually creates a todo for the current user on a merge request.
Manually creates a todo for the current user on a merge request.
If there already exists a todo for the user on that merge request,
If there already exists a todo for the user on that merge request,
status code
`304`
is returned.
status code
`304`
is returned.
...
...
lib/api/merge_requests.rb
View file @
8b5c16e4
...
@@ -28,6 +28,7 @@ module API
...
@@ -28,6 +28,7 @@ module API
optional
:assignee_id
,
type:
Integer
,
desc:
'The ID of a user to assign the merge request'
optional
:assignee_id
,
type:
Integer
,
desc:
'The ID of a user to assign the merge request'
optional
:milestone_id
,
type:
Integer
,
desc:
'The ID of a milestone to assign the merge request'
optional
:milestone_id
,
type:
Integer
,
desc:
'The ID of a milestone to assign the merge request'
optional
:labels
,
type:
String
,
desc:
'Comma-separated list of label names'
optional
:labels
,
type:
String
,
desc:
'Comma-separated list of label names'
optional
:remove_source_branch
,
type:
Boolean
,
desc:
'Remove source branch when merging'
end
end
end
end
...
@@ -75,7 +76,8 @@ module API
...
@@ -75,7 +76,8 @@ module API
post
":id/merge_requests"
do
post
":id/merge_requests"
do
authorize!
:create_merge_request
,
user_project
authorize!
:create_merge_request
,
user_project
mr_params
=
declared_params
mr_params
=
declared_params
(
include_missing:
false
)
mr_params
[
:force_remove_source_branch
]
=
mr_params
.
delete
(
:remove_source_branch
)
if
mr_params
[
:remove_source_branch
].
present?
merge_request
=
::
MergeRequests
::
CreateService
.
new
(
user_project
,
current_user
,
mr_params
).
execute
merge_request
=
::
MergeRequests
::
CreateService
.
new
(
user_project
,
current_user
,
mr_params
).
execute
...
@@ -144,13 +146,15 @@ module API
...
@@ -144,13 +146,15 @@ module API
desc:
'Status of the merge request'
desc:
'Status of the merge request'
use
:optional_params
use
:optional_params
at_least_one_of
:title
,
:target_branch
,
:description
,
:assignee_id
,
at_least_one_of
:title
,
:target_branch
,
:description
,
:assignee_id
,
:milestone_id
,
:labels
,
:state_event
:milestone_id
,
:labels
,
:state_event
,
:remove_source_branch
end
end
put
path
do
put
path
do
merge_request
=
user_project
.
merge_requests
.
find
(
params
.
delete
(
:merge_request_id
))
merge_request
=
user_project
.
merge_requests
.
find
(
params
.
delete
(
:merge_request_id
))
authorize!
:update_merge_request
,
merge_request
authorize!
:update_merge_request
,
merge_request
mr_params
=
declared_params
(
include_missing:
false
)
mr_params
=
declared_params
(
include_missing:
false
)
mr_params
[
:force_remove_source_branch
]
=
mr_params
.
delete
(
:remove_source_branch
)
if
mr_params
[
:remove_source_branch
].
present?
merge_request
=
::
MergeRequests
::
UpdateService
.
new
(
user_project
,
current_user
,
mr_params
).
execute
(
merge_request
)
merge_request
=
::
MergeRequests
::
UpdateService
.
new
(
user_project
,
current_user
,
mr_params
).
execute
(
merge_request
)
...
...
spec/requests/api/merge_requests_spec.rb
View file @
8b5c16e4
...
@@ -234,11 +234,14 @@ describe API::MergeRequests, api: true do
...
@@ -234,11 +234,14 @@ describe API::MergeRequests, api: true do
target_branch:
'master'
,
target_branch:
'master'
,
author:
user
,
author:
user
,
labels:
'label, label2'
,
labels:
'label, label2'
,
milestone_id:
milestone
.
id
milestone_id:
milestone
.
id
,
remove_source_branch:
true
expect
(
response
).
to
have_http_status
(
201
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
[
'title'
]).
to
eq
(
'Test merge_request'
)
expect
(
json_response
[
'title'
]).
to
eq
(
'Test merge_request'
)
expect
(
json_response
[
'labels'
]).
to
eq
([
'label'
,
'label2'
])
expect
(
json_response
[
'labels'
]).
to
eq
([
'label'
,
'label2'
])
expect
(
json_response
[
'milestone'
][
'id'
]).
to
eq
(
milestone
.
id
)
expect
(
json_response
[
'milestone'
][
'id'
]).
to
eq
(
milestone
.
id
)
expect
(
json_response
[
'force_remove_source_branch'
]).
to
be_truthy
end
end
it
"returns 422 when source_branch equals target_branch"
do
it
"returns 422 when source_branch equals target_branch"
do
...
@@ -511,6 +514,13 @@ describe API::MergeRequests, api: true do
...
@@ -511,6 +514,13 @@ describe API::MergeRequests, api: true do
expect
(
json_response
[
'target_branch'
]).
to
eq
(
'wiki'
)
expect
(
json_response
[
'target_branch'
]).
to
eq
(
'wiki'
)
end
end
it
"returns merge_request that removes the source branch"
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
remove_source_branch:
true
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'force_remove_source_branch'
]).
to
be_truthy
end
it
'allows special label names'
do
it
'allows special label names'
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
id
}
"
,
user
),
title:
'new issue'
,
title:
'new issue'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment