Commit 1f5a6eb2 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'mr-commits-api' into 'master'

Add API endpoint to fetch merge request commits list

Fixes #3748 

See merge request !1984
parents 0c377a79 c366e81d
......@@ -7,6 +7,7 @@ v 8.3.0 (unreleased)
- Add ignore whitespace change option to commit view
- Fire update hook from GitLab
- Don't show project fork event as "imported"
- Add API endpoint to fetch merge request commits list
v 8.2.2
- Fix 404 in redirection after removing a project (Stan Hu)
......
......@@ -101,6 +101,43 @@ Parameters:
}
```
## Get single MR commits
Get a list of merge request commits.
```
GET /projects/:id/merge_request/:merge_request_id/commits
```
Parameters:
- `id` (required) - The ID of a project
- `merge_request_id` (required) - The ID of MR
```json
[
{
"id": "ed899a2f4b50b4370feeea94676502b42383c746",
"short_id": "ed899a2f4b5",
"title": "Replace sanitize with escape once",
"author_name": "Dmitriy Zaporozhets",
"author_email": "dzaporozhets@sphereconsultinginc.com",
"created_at": "2012-09-20T11:50:22+03:00",
"message": "Replace sanitize with escape once"
},
{
"id": "6104942438c14ec7bd21c6cd5bd995272b3faff6",
"short_id": "6104942438c",
"title": "Sanitize for network graph",
"author_name": "randx",
"author_email": "dmitriy.zaporozhets@gmail.com",
"created_at": "2012-09-20T09:06:12+03:00",
"message": "Sanitize for network graph"
}
]
```
## Get single MR changes
Shows information about the merge request including its files and changes.
......@@ -159,7 +196,7 @@ Parameters:
"updated_at": "2015-02-02T19:49:26.013Z",
"due_date": null
},
"files": [
"changes": [
{
"old_path": "VERSION",
"new_path": "VERSION",
......
......@@ -76,6 +76,22 @@ module API
present merge_request, with: Entities::MergeRequest
end
# Show MR commits
#
# Parameters:
# id (required) - The ID of a project
# merge_request_id (required) - The ID of MR
#
# Example:
# GET /projects/:id/merge_request/:merge_request_id/commits
#
get ':id/merge_request/:merge_request_id/commits' do
merge_request = user_project.merge_requests.
find(params[:merge_request_id])
authorize! :read_merge_request, merge_request
present merge_request.commits, with: Entities::RepoCommit
end
# Show MR changes
#
# Parameters:
......
......@@ -131,6 +131,23 @@ describe API::API, api: true do
end
end
describe 'GET /projects/:id/merge_request/:merge_request_id/commits' do
context 'valid merge request' do
before { get api("/projects/#{project.id}/merge_request/#{merge_request.id}/commits", user) }
let(:commit) { merge_request.commits.first }
it { expect(response.status).to eq 200 }
it { expect(json_response.size).to eq(merge_request.commits.size) }
it { expect(json_response.first['id']).to eq(commit.id) }
it { expect(json_response.first['title']).to eq(commit.title) }
end
it 'returns a 404 when merge_request_id not found' do
get api("/projects/#{project.id}/merge_request/999/commits", user)
expect(response.status).to eq(404)
end
end
describe 'GET /projects/:id/merge_request/:merge_request_id/changes' do
it 'should return the change information of the merge_request' do
get api("/projects/#{project.id}/merge_request/#{merge_request.id}/changes", user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment