Commit d97ac2f6 authored by Rémy Coutable's avatar Rémy Coutable Committed by Alejandro Rodríguez

Merge branch 'fix-api-iid-filter' into 'master'

Fix IID filter for merge requests and milestones

I updated the example in the docs and added a test. The milestones API was also broken for the same reason.

Related to !7358 and !7373

See merge request !7648
parent dcdb4218
...@@ -11,6 +11,7 @@ GET /projects/:id/merge_requests ...@@ -11,6 +11,7 @@ GET /projects/:id/merge_requests
GET /projects/:id/merge_requests?state=opened GET /projects/:id/merge_requests?state=opened
GET /projects/:id/merge_requests?state=all GET /projects/:id/merge_requests?state=all
GET /projects/:id/merge_requests?iid=42 GET /projects/:id/merge_requests?iid=42
GET /projects/:id/merge_requests?iid[]=42&iid[]=43
``` ```
Parameters: Parameters:
......
...@@ -7,6 +7,7 @@ Returns a list of project milestones. ...@@ -7,6 +7,7 @@ Returns a list of project milestones.
``` ```
GET /projects/:id/milestones GET /projects/:id/milestones
GET /projects/:id/milestones?iid=42 GET /projects/:id/milestones?iid=42
GET /projects/:id/milestones?iid[]=42&iid[]=43
GET /projects/:id/milestones?state=active GET /projects/:id/milestones?state=active
GET /projects/:id/milestones?state=closed GET /projects/:id/milestones?state=closed
``` ```
...@@ -16,7 +17,7 @@ Parameters: ...@@ -16,7 +17,7 @@ Parameters:
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- | | --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of a project | | `id` | integer | yes | The ID of a project |
| `iid` | integer | optional | Return only the milestone having the given `iid` | | `iid` | Array[integer] | optional | Return only the milestone having the given `iid` |
| `state` | string | optional | Return only `active` or `closed` milestones` | | `state` | string | optional | Return only `active` or `closed` milestones` |
```bash ```bash
......
...@@ -41,15 +41,13 @@ module API ...@@ -41,15 +41,13 @@ module API
desc: 'Return merge requests ordered by `created_at` or `updated_at` fields.' desc: 'Return merge requests ordered by `created_at` or `updated_at` fields.'
optional :sort, type: String, values: %w[asc desc], default: 'desc', optional :sort, type: String, values: %w[asc desc], default: 'desc',
desc: 'Return merge requests sorted in `asc` or `desc` order.' desc: 'Return merge requests sorted in `asc` or `desc` order.'
optional :iid, type: Integer, desc: 'The IID of the merge requests' optional :iid, type: Array[Integer], desc: 'The IID of the merge requests'
end end
get ":id/merge_requests" do get ":id/merge_requests" do
authorize! :read_merge_request, user_project authorize! :read_merge_request, user_project
merge_requests = user_project.merge_requests.inc_notes_with_associations
unless params[:iid].nil? merge_requests = user_project.merge_requests.inc_notes_with_associations
merge_requests = filter_by_iid(merge_requests, params[:iid]) merge_requests = filter_by_iid(merge_requests, params[:iid]) if params[:iid].present?
end
merge_requests = merge_requests =
case params[:state] case params[:state]
......
...@@ -28,7 +28,7 @@ module API ...@@ -28,7 +28,7 @@ module API
params do params do
optional :state, type: String, values: %w[active closed all], default: 'all', optional :state, type: String, values: %w[active closed all], default: 'all',
desc: 'Return "active", "closed", or "all" milestones' desc: 'Return "active", "closed", or "all" milestones'
optional :iid, type: Integer, desc: 'The IID of the milestone' optional :iid, type: Array[Integer], desc: 'The IID of the milestone'
end end
get ":id/milestones" do get ":id/milestones" do
authorize! :read_milestone, user_project authorize! :read_milestone, user_project
......
...@@ -169,6 +169,16 @@ describe API::API, api: true do ...@@ -169,6 +169,16 @@ describe API::API, api: true do
expect(json_response.first['id']).to eq merge_request.id expect(json_response.first['id']).to eq merge_request.id
end end
it 'returns merge_request by iid array' do
get api("/projects/#{project.id}/merge_requests", user), iid: [merge_request.iid, merge_request_closed.iid]
expect(response).to have_http_status(200)
expect(json_response).to be_an Array
expect(json_response.length).to eq(2)
expect(json_response.first['title']).to eq merge_request_closed.title
expect(json_response.first['id']).to eq merge_request_closed.id
end
it "returns a 404 error if merge_request_id not found" do it "returns a 404 error if merge_request_id not found" do
get api("/projects/#{project.id}/merge_requests/999", user) get api("/projects/#{project.id}/merge_requests/999", user)
expect(response).to have_http_status(404) expect(response).to have_http_status(404)
......
...@@ -61,6 +61,15 @@ describe API::API, api: true do ...@@ -61,6 +61,15 @@ describe API::API, api: true do
expect(json_response.first['id']).to eq closed_milestone.id expect(json_response.first['id']).to eq closed_milestone.id
end end
it 'returns a project milestone by iid array' do
get api("/projects/#{project.id}/milestones", user), iid: [milestone.iid, closed_milestone.iid]
expect(response).to have_http_status(200)
expect(json_response.size).to eq(2)
expect(json_response.first['title']).to eq milestone.title
expect(json_response.first['id']).to eq milestone.id
end
it 'returns 401 error if user not authenticated' do it 'returns 401 error if user not authenticated' do
get api("/projects/#{project.id}/milestones/#{milestone.id}") get api("/projects/#{project.id}/milestones/#{milestone.id}")
......
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