BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
fffa19cb
Commit
fffa19cb
authored
Mar 28, 2018
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'expose-commits-mr-api' into 'master'
Allow merge requests related to a commit to be found via API See merge request gitlab-org/gitlab-ce!18004
parents
d7a9df68
847671e0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
0 deletions
+116
-0
expose-commits-mr-api.yml
changelogs/unreleased/expose-commits-mr-api.yml
+5
-0
commits.md
doc/api/commits.md
+68
-0
commits.rb
lib/api/commits.rb
+14
-0
commits_spec.rb
spec/requests/api/commits_spec.rb
+29
-0
No files found.
changelogs/unreleased/expose-commits-mr-api.yml
0 → 100644
View file @
fffa19cb
---
title
:
Allow merge requests related to a commit to be found via API
merge_request
:
author
:
type
:
added
doc/api/commits.md
View file @
fffa19cb
...
...
@@ -536,6 +536,74 @@ Example response:
}
```
## List Merge Requests associated with a commit
Get a list of Merge Requests related to the specified commit.
```
GET /projects/:id/repository/commits/:sha/merge_requests
```
| 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
|
`sha`
| string | yes | The commit SHA
```bash
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/5/repository/commits/af5b13261899fb2c0db30abdd0af8b07cb44fdc5/merge_requests"
```
Example response:
```
json
[
{
"id"
:
45
,
"iid"
:
1
,
"project_id"
:
35
,
"title"
:
"Add new file"
,
"description"
:
""
,
"state"
:
"opened"
,
"created_at"
:
"2018-03-26T17:26:30.916Z"
,
"updated_at"
:
"2018-03-26T17:26:30.916Z"
,
"target_branch"
:
"master"
,
"source_branch"
:
"test-branch"
,
"upvotes"
:
0
,
"downvotes"
:
0
,
"author"
:
{
"web_url"
:
"https://gitlab.example.com/thedude"
,
"name"
:
"Jeff Lebowski"
,
"avatar_url"
:
"https://gitlab.example.com/uploads/user/avatar/28/The-Big-Lebowski-400-400.png"
,
"username"
:
"thedude"
,
"state"
:
"active"
,
"id"
:
28
},
"assignee"
:
null
,
"source_project_id"
:
35
,
"target_project_id"
:
35
,
"labels"
:[
],
"work_in_progress"
:
false
,
"milestone"
:
null
,
"merge_when_pipeline_succeeds"
:
false
,
"merge_status"
:
"can_be_merged"
,
"sha"
:
"af5b13261899fb2c0db30abdd0af8b07cb44fdc5"
,
"merge_commit_sha"
:
null
,
"user_notes_count"
:
0
,
"discussion_locked"
:
null
,
"should_remove_source_branch"
:
null
,
"force_remove_source_branch"
:
false
,
"web_url"
:
"http://https://gitlab.example.com/root/test-project/merge_requests/1"
,
"time_stats"
:{
"time_estimate"
:
0
,
"total_time_spent"
:
0
,
"human_time_estimate"
:
null
,
"human_total_time_spent"
:
null
}
}
]
```
[
ce-6096
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/6096
"Multi-file commit"
[
ce-8047
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/8047
[
ce-15026
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/15026
lib/api/commits.rb
View file @
fffa19cb
...
...
@@ -231,6 +231,20 @@ module API
render_api_error!
(
"Failed to save note
#{
note
.
errors
.
messages
}
"
,
400
)
end
end
desc
'Get Merge Requests associated with a commit'
do
success
Entities
::
MergeRequestBasic
end
params
do
requires
:sha
,
type:
String
,
desc:
'A commit sha, or the name of a branch or tag on which to find Merge Requests'
use
:pagination
end
get
':id/repository/commits/:sha/merge_requests'
,
requirements:
API
::
COMMIT_ENDPOINT_REQUIREMENTS
do
commit
=
user_project
.
commit
(
params
[
:sha
])
not_found!
'Commit'
unless
commit
present
paginate
(
commit
.
merge_requests
),
with:
Entities
::
MergeRequestBasic
end
end
end
end
spec/requests/api/commits_spec.rb
View file @
fffa19cb
...
...
@@ -1141,4 +1141,33 @@ describe API::Commits do
end
end
end
describe
'GET /projects/:id/repository/commits/:sha/merge_requests'
do
let!
(
:project
)
{
create
(
:project
,
:repository
,
:private
)
}
let!
(
:merged_mr
)
{
create
(
:merge_request
,
source_project:
project
,
source_branch:
'master'
,
target_branch:
'feature'
)
}
let
(
:commit
)
{
merged_mr
.
merge_request_diff
.
commits
.
last
}
it
'returns the correct merge request'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/merge_requests"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
length
).
to
eq
(
1
)
expect
(
json_response
[
0
][
'id'
]).
to
eq
(
merged_mr
.
id
)
end
it
'returns 403 for an unauthorized user'
do
project
.
add_guest
(
user
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/
#{
commit
.
id
}
/merge_requests"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
it
'responds 404 when the commit does not exist'
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/commits/a7d26f00c35b/merge_requests"
,
user
)
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
end
end
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