Make it possible to query scope as scope[]=

Since issues also accepts the query parameter iids[]=, also make it
possible query scope like that.
This commit is contained in:
Toon Claes 2017-03-07 20:54:39 +01:00
parent f372400673
commit 901fbda67c
3 changed files with 13 additions and 11 deletions

View File

@ -14,7 +14,7 @@ GET /projects/:id/jobs
| `scope` | string **or** array of strings | no | The scope of jobs to show, one or array of: `created`, `pending`, `running`, `failed`, `success`, `canceled`, `skipped`; showing all jobs if none provided |
```
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" 'https://gitlab.example.com/api/v4/projects/1/jobs?scope%5B0%5D=pending&scope%5B1%5D=running'
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" 'https://gitlab.example.com/api/v4/projects/1/jobs?scope[]=pending&scope[]=running'
```
Example of response
@ -123,14 +123,14 @@ Get a list of jobs for a pipeline.
GET /projects/:id/pipeline/:pipeline_id/jobs
```
| Attribute | Type | Required | Description |
|--------------|--------------------------------|----------|----------------------|
| `id` | integer | yes | The ID of a project |
| `pipelin_id` | integer | yes | The ID of a pipeline |
| `scope` | string **or** array of strings | no | The scope of jobs to show, one or array of: `created`, `pending`, `running`, `failed`, `success`, `canceled`, `skipped`; showing all jobs if none provided |
| Attribute | Type | Required | Description |
|---------------|--------------------------------|----------|----------------------|
| `id` | integer | yes | The ID of a project |
| `pipeline_id` | integer | yes | The ID of a pipeline |
| `scope` | string **or** array of strings | no | The scope of jobs to show, one or array of: `created`, `pending`, `running`, `failed`, `success`, `canceled`, `skipped`; showing all jobs if none provided |
```
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" 'https://gitlab.example.com/api/v4/projects/1/pipelines/6/jobs?scope%5B0%5D=pending&scope%5B1%5D=running'
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" 'https://gitlab.example.com/api/v4/projects/1/pipelines/6/jobs?scope[]=pending&scope[]=running'
```
Example of response

View File

@ -18,6 +18,8 @@ module API
[scope]
when Hashie::Mash
scope.values
when Hashie::Array
scope
else
['unknown']
end

View File

@ -51,7 +51,7 @@ describe API::Jobs, api: true do
end
context 'filter project with array of scope elements' do
let(:query) { { 'scope[0]' => 'pending', 'scope[1]' => 'running' } }
let(:query) { { scope: %w(pending running) } }
it do
expect(response).to have_http_status(200)
@ -60,7 +60,7 @@ describe API::Jobs, api: true do
end
context 'respond 400 when scope contains invalid state' do
let(:query) { { 'scope[0]' => 'unknown', 'scope[1]' => 'running' } }
let(:query) { { scope: %w(unknown running) } }
it { expect(response).to have_http_status(400) }
end
@ -114,7 +114,7 @@ describe API::Jobs, api: true do
end
context 'filter jobs with array of scope elements' do
let(:query) { { 'scope[0]' => 'pending', 'scope[1]' => 'running' } }
let(:query) { { scope: %w(pending running) } }
it do
expect(response).to have_http_status(200)
@ -123,7 +123,7 @@ describe API::Jobs, api: true do
end
context 'respond 400 when scope contains invalid state' do
let(:query) { { 'scope[0]' => 'unknown', 'scope[1]' => 'running' } }
let(:query) { { scope: %w(unknown running) } }
it { expect(response).to have_http_status(400) }
end