Add API endpoint to fetch merge request commits list
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
0ccd7de7f3
commit
0b68a0e79e
4 changed files with 73 additions and 0 deletions
|
@ -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,45 @@ Parameters:
|
|||
}
|
||||
```
|
||||
|
||||
## Get single MR commits
|
||||
|
||||
Get a list of repository commits in a merge request.
|
||||
|
||||
```
|
||||
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",
|
||||
"allow_failure": false
|
||||
},
|
||||
{
|
||||
"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",
|
||||
"allow_failure": false
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## Get single MR changes
|
||||
|
||||
Shows information about the merge request including its files and changes.
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue