summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/finders/pipelines_finder.rb19
-rw-r--r--lib/api/pipelines.rb2
-rw-r--r--spec/finders/pipelines_finder_spec.rb4
-rw-r--r--spec/requests/api/pipelines_spec.rb4
4 files changed, 8 insertions, 21 deletions
diff --git a/app/finders/pipelines_finder.rb b/app/finders/pipelines_finder.rb
index 7935878d1d5..c6666802b7f 100644
--- a/app/finders/pipelines_finder.rb
+++ b/app/finders/pipelines_finder.rb
@@ -54,22 +54,9 @@ class PipelinesFinder
end
def by_status(items)
- case params[:status]
- when 'running'
- items.running
- when 'pending'
- items.pending
- when 'success'
- items.success
- when 'failed'
- items.failed
- when 'canceled'
- items.canceled
- when 'skipped'
- items.skipped
- else
- items
- end
+ return items unless HasStatus::AVAILABLE_STATUSES.include?(params[:status])
+
+ items.where(status: params[:status])
end
def by_ref(items)
diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb
index b0f586b08da..29757dd9935 100644
--- a/lib/api/pipelines.rb
+++ b/lib/api/pipelines.rb
@@ -16,7 +16,7 @@ module API
use :pagination
optional :scope, type: String, values: %w[running pending finished branches tags],
desc: 'The scope of pipelines'
- optional :status, type: String, values: %w[running pending success failed canceled skipped],
+ optional :status, type: String, values: HasStatus::AVAILABLE_STATUSES,
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'
diff --git a/spec/finders/pipelines_finder_spec.rb b/spec/finders/pipelines_finder_spec.rb
index cffe5a46622..276a680b457 100644
--- a/spec/finders/pipelines_finder_spec.rb
+++ b/spec/finders/pipelines_finder_spec.rb
@@ -60,13 +60,13 @@ describe PipelinesFinder do
end
end
- %w[running pending success failed canceled skipped].each do |target|
+ HasStatus::AVAILABLE_STATUSES.each do |target|
context "when status is #{target}" do
let(:params) { { status: target } }
let!(:pipeline) { create(:ci_pipeline, project: project, status: target) }
before do
- exception_status = %w[running pending success failed canceled skipped] - [target]
+ exception_status = HasStatus::AVAILABLE_STATUSES - [target]
create(:ci_pipeline, project: project, status: exception_status.sample)
end
diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb
index 6406b60219c..b7d61b2cd7c 100644
--- a/spec/requests/api/pipelines_spec.rb
+++ b/spec/requests/api/pipelines_spec.rb
@@ -95,11 +95,11 @@ describe API::Pipelines do
end
end
- %w[running pending success failed canceled skipped].each do |target|
+ HasStatus::AVAILABLE_STATUSES.each do |target|
context "when status is #{target}" do
before do
create(:ci_pipeline, project: project, status: target)
- exception_status = %w[running pending success failed canceled skipped] - [target]
+ exception_status = HasStatus::AVAILABLE_STATUSES - [target]
create(:ci_pipeline, project: project, status: exception_status.sample)
end