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
Léo-Paul Géneau
gitlab-ce
Commits
9f287298
Commit
9f287298
authored
Nov 22, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a rebase API endpoint for merge requests
parent
0afce35d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
0 deletions
+76
-0
changelogs/unreleased/33705-merge-request-rebase-api.yml
changelogs/unreleased/33705-merge-request-rebase-api.yml
+5
-0
doc/api/merge_requests.md
doc/api/merge_requests.md
+25
-0
lib/api/merge_requests.rb
lib/api/merge_requests.rb
+26
-0
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+20
-0
No files found.
changelogs/unreleased/33705-merge-request-rebase-api.yml
0 → 100644
View file @
9f287298
---
title
:
Add a rebase API endpoint for merge requests
merge_request
:
23296
author
:
type
:
added
doc/api/merge_requests.md
View file @
9f287298
...
...
@@ -1206,6 +1206,31 @@ Parameters:
}
```
## Rebase a merge request
Automatically rebase the
`source_branch`
of the merge request against its
`target_branch`
.
If you don't have permissions to push to the merge request's source branch -
you'll get a
`403 Forbidden`
response.
```
PUT /projects/:id/merge_requests/:merge_request_iid/rebase
```
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user |
|
`merge_request_iid`
| integer | yes | The internal ID of the merge request |
```
bash
curl
--header
"PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK"
https://gitlab.example.com/api/v4/projects/76/merge_requests/1/rebase
```
This is an asynchronous request. The API will return an empty
`202 Accepted`
response if the request is enqueued successfully. You should poll the
[
Get single MR
](
#get-single-mr
)
endpoint to determine success or failure.
## Comments on merge requests
Comments are done via the
[
notes
](
notes.md
)
resource.
...
...
lib/api/merge_requests.rb
View file @
9f287298
...
...
@@ -74,6 +74,19 @@ module API
options
end
def
authorize_push_to_merge_request!
(
merge_request
)
forbidden!
(
'Source branch does not exist'
)
unless
merge_request
.
source_branch_exists?
user_access
=
Gitlab
::
UserAccess
.
new
(
current_user
,
project:
merge_request
.
source_project
)
forbidden!
(
'Cannot push to source branch'
)
unless
user_access
.
can_push_to_branch?
(
merge_request
.
source_branch
)
end
params
:merge_requests_params
do
optional
:state
,
type:
String
,
values:
%w[opened closed locked merged all]
,
default:
'all'
,
desc:
'Return opened, closed, locked, merged, or all merge requests'
...
...
@@ -378,6 +391,19 @@ module API
.
cancel
(
merge_request
)
end
desc
'Rebase the merge request against its target branch'
do
detail
'This feature was added in GitLab 11.6'
end
put
':id/merge_requests/:merge_request_iid/rebase'
do
merge_request
=
find_project_merge_request
(
params
[
:merge_request_iid
])
authorize_push_to_merge_request!
(
merge_request
)
RebaseWorker
.
perform_async
(
merge_request
.
id
,
current_user
.
id
)
status
:accepted
end
desc
'List issues that will be closed on merge'
do
success
Entities
::
MRNote
end
...
...
spec/requests/api/merge_requests_spec.rb
View file @
9f287298
...
...
@@ -1181,6 +1181,26 @@ describe API::MergeRequests do
end
end
describe
'PUT :id/merge_requests/:merge_request_iid/rebase'
do
it
'enques a rebase of the merge request against the target branch'
do
Sidekiq
::
Testing
.
fake!
do
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/rebase"
,
user
)
end
expect
(
response
).
to
have_gitlab_http_status
(
202
)
expect
(
RebaseWorker
.
jobs
.
size
).
to
eq
(
1
)
end
it
'returns 403 if the user cannot push to the branch'
do
guest
=
create
(
:user
)
project
.
add_guest
(
guest
)
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/rebase"
,
guest
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
end
describe
'Time tracking'
do
let
(
:issuable
)
{
merge_request
}
...
...
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