summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToon Claes <toon@gitlab.com>2017-03-07 20:54:39 +0100
committerToon Claes <toon@gitlab.com>2017-03-07 23:45:32 +0100
commit901fbda67c2c8781bb8bdb0b1a7d7869a81bc93e (patch)
treee679cdf0193608f70c7922658c97e754244b3b26
parentf37240067301548a41a6257792d3926b68328e62 (diff)
downloadgitlab-ce-901fbda67c2c8781bb8bdb0b1a7d7869a81bc93e.tar.gz
Make it possible to query scope as scope[]=
Since issues also accepts the query parameter iids[]=, also make it possible query scope like that.
-rw-r--r--doc/api/jobs.md14
-rw-r--r--lib/api/jobs.rb2
-rw-r--r--spec/requests/api/jobs_spec.rb8
3 files changed, 13 insertions, 11 deletions
diff --git a/doc/api/jobs.md b/doc/api/jobs.md
index e503ee73164..7340123e09d 100644
--- a/doc/api/jobs.md
+++ b/doc/api/jobs.md
@@ -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
diff --git a/lib/api/jobs.rb b/lib/api/jobs.rb
index af8f4b1e759..3a1a393c940 100644
--- a/lib/api/jobs.rb
+++ b/lib/api/jobs.rb
@@ -18,6 +18,8 @@ module API
[scope]
when Hashie::Mash
scope.values
+ when Hashie::Array
+ scope
else
['unknown']
end
diff --git a/spec/requests/api/jobs_spec.rb b/spec/requests/api/jobs_spec.rb
index cfd7de7e4e9..9450701064b 100644
--- a/spec/requests/api/jobs_spec.rb
+++ b/spec/requests/api/jobs_spec.rb
@@ -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