Commit 901fbda6 authored by Toon Claes's avatar Toon Claes

Make it possible to query scope as scope[]=

Since issues also accepts the query parameter iids[]=, also make it
possible query scope like that.
parent f3724006
...@@ -14,7 +14,7 @@ GET /projects/:id/jobs ...@@ -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 | | `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 Example of response
...@@ -124,13 +124,13 @@ GET /projects/:id/pipeline/:pipeline_id/jobs ...@@ -124,13 +124,13 @@ GET /projects/:id/pipeline/:pipeline_id/jobs
``` ```
| Attribute | Type | Required | Description | | Attribute | Type | Required | Description |
|--------------|--------------------------------|----------|----------------------| |---------------|--------------------------------|----------|----------------------|
| `id` | integer | yes | The ID of a project | | `id` | integer | yes | The ID of a project |
| `pipelin_id` | integer | yes | The ID of a pipeline | | `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 | | `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 Example of response
......
...@@ -18,6 +18,8 @@ module API ...@@ -18,6 +18,8 @@ module API
[scope] [scope]
when Hashie::Mash when Hashie::Mash
scope.values scope.values
when Hashie::Array
scope
else else
['unknown'] ['unknown']
end end
......
...@@ -51,7 +51,7 @@ describe API::Jobs, api: true do ...@@ -51,7 +51,7 @@ describe API::Jobs, api: true do
end end
context 'filter project with array of scope elements' do 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 it do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -60,7 +60,7 @@ describe API::Jobs, api: true do ...@@ -60,7 +60,7 @@ describe API::Jobs, api: true do
end end
context 'respond 400 when scope contains invalid state' do 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) } it { expect(response).to have_http_status(400) }
end end
...@@ -114,7 +114,7 @@ describe API::Jobs, api: true do ...@@ -114,7 +114,7 @@ describe API::Jobs, api: true do
end end
context 'filter jobs with array of scope elements' do 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 it do
expect(response).to have_http_status(200) expect(response).to have_http_status(200)
...@@ -123,7 +123,7 @@ describe API::Jobs, api: true do ...@@ -123,7 +123,7 @@ describe API::Jobs, api: true do
end end
context 'respond 400 when scope contains invalid state' do 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) } it { expect(response).to have_http_status(400) }
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