diff options
author | Rémy Coutable <remy@rymai.me> | 2017-02-17 12:48:29 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-02-17 12:48:29 +0000 |
commit | 5cc9ebbe14ce35de1ec45fc7abce3aa9f408ddf2 (patch) | |
tree | 0be1ab14a5df60f6b1459350ec8692f2a9cdf80a | |
parent | 35824650433c319a817428029b096743a18caa6f (diff) | |
parent | aa7c8be5c654000fe71a59e4f8ff22bd3a3e1219 (diff) | |
download | gitlab-ce-5cc9ebbe14ce35de1ec45fc7abce3aa9f408ddf2.tar.gz |
Merge branch '22018-api-milestone-merge-requests' into 'master'
Add API endpoint to get all milestone merge requests
Closes #22018
See merge request !9298
-rw-r--r-- | changelogs/unreleased/22018-api-milestone-merge-requests.yml | 4 | ||||
-rw-r--r-- | doc/api/milestones.md | 13 | ||||
-rw-r--r-- | lib/api/milestones.rb | 22 | ||||
-rw-r--r-- | spec/requests/api/milestones_spec.rb | 36 |
4 files changed, 75 insertions, 0 deletions
diff --git a/changelogs/unreleased/22018-api-milestone-merge-requests.yml b/changelogs/unreleased/22018-api-milestone-merge-requests.yml new file mode 100644 index 00000000000..ccad2ec838c --- /dev/null +++ b/changelogs/unreleased/22018-api-milestone-merge-requests.yml @@ -0,0 +1,4 @@ +--- +title: Adds API endpoint to fetch all merge request for a single milestone +merge_request: +author: Joren De Groof diff --git a/doc/api/milestones.md b/doc/api/milestones.md index 12497acff98..bf7dcc008e9 100644 --- a/doc/api/milestones.md +++ b/doc/api/milestones.md @@ -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 diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb index 3c373a84ec5..0b4ed76b35c 100644 --- a/lib/api/milestones.rb +++ b/lib/api/milestones.rb @@ -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 diff --git a/spec/requests/api/milestones_spec.rb b/spec/requests/api/milestones_spec.rb index 8beef821d6c..7bb208721a1 100644 --- a/spec/requests/api/milestones_spec.rb +++ b/spec/requests/api/milestones_spec.rb @@ -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 |