diff options
author | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-03-08 20:24:00 +0900 |
---|---|---|
committer | Shinya Maeda <gitlab.shinyamaeda@gmail.com> | 2017-05-03 02:11:51 +0900 |
commit | 175800299bf497591e625e82fd71420644c0bc6b (patch) | |
tree | dd2a089a7124806a6cd71ac2208268a16f75dc71 | |
parent | 83d02a0b609ea71ef8448b9012221962dda69aba (diff) | |
download | gitlab-ce-175800299bf497591e625e82fd71420644c0bc6b.tar.gz |
Add name(User)
-rw-r--r-- | app/finders/pipelines_finder.rb | 8 | ||||
-rw-r--r-- | doc/api/pipelines.md | 3 | ||||
-rw-r--r-- | lib/api/pipelines.rb | 3 | ||||
-rw-r--r-- | spec/finders/pipelines_finder_spec.rb | 30 |
4 files changed, 36 insertions, 8 deletions
diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb index c01a1a73666..10c8f5e0b2e 100644 --- a/app/finders/pipelines_finder.rb +++ b/app/finders/pipelines_finder.rb @@ -79,6 +79,14 @@ class PipelinesFinder end end + def by_name(items) + if params[:name].present? + items.joins(:user).where("users.name = ?", params[:name]) + else + items + end + end + def by_username(items) if params[:username].present? items.joins(:user).where("users.username = ?", params[:username]) diff --git a/doc/api/pipelines.md b/doc/api/pipelines.md index 48e0d10180b..b843d64e000 100644 --- a/doc/api/pipelines.md +++ b/doc/api/pipelines.md @@ -15,7 +15,8 @@ GET /projects/:id/pipelines | `status` | string | no | The status of pipelines, one of: `running`, `pending`, `success`, `failed`, `canceled`, `skipped`; | | `ref` | string | no | The ref of pipelines | | `yaml_errors`| string | no | If true, returns only yaml error pipelines | -| `username`| string | no | The name of user who triggered pipelines | +| `name`| string | no | The name of user who triggered pipelines | +| `username`| string | no | The username of user who triggered pipelines | | `order_by`| string | no | Return requests ordered by `id`, `status`, `ref`, `username`, `started_at`, `finished_at`, `created_at` or `updated_at` fields. Default is `id` | | `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` | diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb index 986dd607e23..79eea7e2e28 100644 --- a/lib/api/pipelines.rb +++ b/lib/api/pipelines.rb @@ -20,7 +20,8 @@ module API desc: 'The status of pipelines' optional :ref, type: String, desc: 'The ref of pipelines' optional :yaml_errors, type: Boolean, desc: 'If true, returns only yaml error pipelines' - optional :username, type: String, desc: 'The name of user who triggered pipelines' + optional :name, type: String, desc: 'The name of user who triggered pipelines' + optional :username, type: String, desc: 'The username of user who triggered pipelines' optional :order_by, type: String, values: %w[id status ref username started_at finished_at created_at updated_at], default: 'id', desc: 'The order_by which is combined with a sort' optional :sort, type: String, values: %w[asc desc], default: 'desc', diff --git a/spec/finders/pipelines_finder_spec.rb b/spec/finders/pipelines_finder_spec.rb index 3a840eca44f..8e214a71a32 100644 --- a/spec/finders/pipelines_finder_spec.rb +++ b/spec/finders/pipelines_finder_spec.rb @@ -134,13 +134,31 @@ describe PipelinesFinder do end context 'when a ref does not exist' do - let(:params) { { ref: 'unique-ref' } } + let(:params) { { ref: 'invalid-ref' } } it 'selects nothing' do expect(subject).to be_empty end end - end + end + + context 'when a name is passed' do + context 'when a name exists' do + let(:params) { { name: user1.name } } + + it 'selects all pipelines which belong to the name' do + expect(subject).to match_array(Ci::Pipeline.where(user: user1)) + end + end + + context 'when a name does not exist' do + let(:params) { { name: 'invalid-name' } } + + it 'selects nothing' do + expect(subject).to be_empty + end + end + end context 'when a username is passed' do context 'when a username exists' do @@ -152,13 +170,13 @@ describe PipelinesFinder do end context 'when a username does not exist' do - let(:params) { { username: 'unique-username' } } + let(:params) { { username: 'invalid-username' } } it 'selects nothing' do expect(subject).to be_empty end end - end + end context 'when a yaml_errors is passed' do context 'when yaml_errors is true' do @@ -204,7 +222,7 @@ describe PipelinesFinder do end context 'when order_by does not exist' do - let(:params) { { order_by: 'abnormal_column', sort: 'desc' } } + let(:params) { { order_by: 'invalid_column', sort: 'desc' } } it 'sorts by default' do expect(subject).to match_array(Ci::Pipeline.order(id: :desc)) @@ -212,7 +230,7 @@ describe PipelinesFinder do end context 'when sort does not exist' do - let(:params) { { order_by: 'created_at', sort: 'abnormal_sort' } } + let(:params) { { order_by: 'created_at', sort: 'invalid_sort' } } it 'sorts by default' do expect(subject).to match_array(Ci::Pipeline.order(id: :desc)) |