Commit 17580029 authored by Shinya Maeda's avatar Shinya Maeda

Add name(User)

parent 83d02a0b
...@@ -79,6 +79,14 @@ class PipelinesFinder ...@@ -79,6 +79,14 @@ class PipelinesFinder
end end
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) def by_username(items)
if params[:username].present? if params[:username].present?
items.joins(:user).where("users.username = ?", params[:username]) items.joins(:user).where("users.username = ?", params[:username])
......
...@@ -15,7 +15,8 @@ GET /projects/:id/pipelines ...@@ -15,7 +15,8 @@ GET /projects/:id/pipelines
| `status` | string | no | The status of pipelines, one of: `running`, `pending`, `success`, `failed`, `canceled`, `skipped`; | | `status` | string | no | The status of pipelines, one of: `running`, `pending`, `success`, `failed`, `canceled`, `skipped`; |
| `ref` | string | no | The ref of pipelines | | `ref` | string | no | The ref of pipelines |
| `yaml_errors`| string | no | If true, returns only yaml error 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` | | `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` | | `sort` | string | no | Return requests sorted in `asc` or `desc` order. Default is `desc` |
......
...@@ -20,7 +20,8 @@ module API ...@@ -20,7 +20,8 @@ module API
desc: 'The status of pipelines' desc: 'The status of pipelines'
optional :ref, type: String, desc: 'The ref 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 :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', 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' desc: 'The order_by which is combined with a sort'
optional :sort, type: String, values: %w[asc desc], default: 'desc', optional :sort, type: String, values: %w[asc desc], default: 'desc',
......
...@@ -134,7 +134,25 @@ describe PipelinesFinder do ...@@ -134,7 +134,25 @@ describe PipelinesFinder do
end end
context 'when a ref does not exist' do 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
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 it 'selects nothing' do
expect(subject).to be_empty expect(subject).to be_empty
...@@ -152,7 +170,7 @@ describe PipelinesFinder do ...@@ -152,7 +170,7 @@ describe PipelinesFinder do
end end
context 'when a username does not exist' do context 'when a username does not exist' do
let(:params) { { username: 'unique-username' } } let(:params) { { username: 'invalid-username' } }
it 'selects nothing' do it 'selects nothing' do
expect(subject).to be_empty expect(subject).to be_empty
...@@ -204,7 +222,7 @@ describe PipelinesFinder do ...@@ -204,7 +222,7 @@ describe PipelinesFinder do
end end
context 'when order_by does not exist' do 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 it 'sorts by default' do
expect(subject).to match_array(Ci::Pipeline.order(id: :desc)) expect(subject).to match_array(Ci::Pipeline.order(id: :desc))
...@@ -212,7 +230,7 @@ describe PipelinesFinder do ...@@ -212,7 +230,7 @@ describe PipelinesFinder do
end end
context 'when sort does not exist' do 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 it 'sorts by default' do
expect(subject).to match_array(Ci::Pipeline.order(id: :desc)) expect(subject).to match_array(Ci::Pipeline.order(id: :desc))
......
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