Add API endpoint to get all milestone merge requests

This commit is contained in:
Joren De Groof 2017-02-16 10:08:18 +01:00
parent b08be16598
commit aa7c8be5c6
4 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,4 @@
---
title: Adds API endpoint to fetch all merge request for a single milestone
merge_request:
author: Joren De Groof

View file

@ -103,3 +103,16 @@ Parameters:
- `id` (required) - The ID of a project
- `milestone_id` (required) - The ID of a project milestone
## Get all merge requests assigned to a single milestone
Gets all merge requests assigned to a single project milestone.
```
GET /projects/:id/milestones/:milestone_id/merge_requests
```
Parameters:
- `id` (required) - The ID of a project
- `milestone_id` (required) - The ID of a project milestone

View file

@ -120,6 +120,28 @@ module API
issues = IssuesFinder.new(current_user, finder_params).execute
present paginate(issues), with: Entities::Issue, current_user: current_user, project: user_project
end
desc 'Get all merge requests for a single project milestone' do
detail 'This feature was introduced in GitLab 9.'
success Entities::MergeRequest
end
params do
requires :milestone_id, type: Integer, desc: 'The ID of a project milestone'
use :pagination
end
get ':id/milestones/:milestone_id/merge_requests' do
authorize! :read_milestone, user_project
milestone = user_project.milestones.find(params[:milestone_id])
finder_params = {
project_id: user_project.id,
milestone_id: milestone.id
}
merge_requests = MergeRequestsFinder.new(current_user, finder_params).execute
present paginate(merge_requests), with: Entities::MergeRequest, current_user: current_user, project: user_project
end
end
end
end

View file

@ -229,4 +229,40 @@ describe API::Milestones, api: true do
end
end
end
describe 'GET /projects/:id/milestones/:milestone_id/merge_requests' do
let(:merge_request) { create(:merge_request, source_project: project) }
before do
milestone.merge_requests << merge_request
end
it 'returns project merge_requests for a particular milestone' do
get api("/projects/#{project.id}/milestones/#{milestone.id}/merge_requests", user)
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.size).to eq(1)
expect(json_response.first['title']).to eq(merge_request.title)
expect(json_response.first['milestone']['title']).to eq(milestone.title)
end
it 'returns a 404 error if milestone id not found' do
get api("/projects/#{project.id}/milestones/1234/merge_requests", user)
expect(response).to have_http_status(404)
end
it 'returns a 404 if the user has no access to the milestone' do
new_user = create :user
get api("/projects/#{project.id}/milestones/#{milestone.id}/merge_requests", new_user)
expect(response).to have_http_status(404)
end
it 'returns a 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}/merge_requests")
expect(response).to have_http_status(401)
end
end
end