Commit aa7c8be5 authored by Joren De Groof's avatar Joren De Groof

Add API endpoint to get all milestone merge requests

parent b08be165
---
title: Adds API endpoint to fetch all merge request for a single milestone
merge_request:
author: Joren De Groof
......@@ -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
\ No newline at end of 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
......@@ -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
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