Commit 0a36bfa9 authored by Shinya Maeda's avatar Shinya Maeda

Use HasStatus::AVAILABLE_STATUSES instead of hard coding

parent 4bd0d8e4
...@@ -54,22 +54,9 @@ class PipelinesFinder ...@@ -54,22 +54,9 @@ class PipelinesFinder
end end
def by_status(items) def by_status(items)
case params[:status] return items unless HasStatus::AVAILABLE_STATUSES.include?(params[:status])
when 'running'
items.running items.where(status: params[:status])
when 'pending'
items.pending
when 'success'
items.success
when 'failed'
items.failed
when 'canceled'
items.canceled
when 'skipped'
items.skipped
else
items
end
end end
def by_ref(items) def by_ref(items)
......
...@@ -16,7 +16,7 @@ module API ...@@ -16,7 +16,7 @@ module API
use :pagination use :pagination
optional :scope, type: String, values: %w[running pending finished branches tags], optional :scope, type: String, values: %w[running pending finished branches tags],
desc: 'The scope of pipelines' 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' 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'
......
...@@ -60,13 +60,13 @@ describe PipelinesFinder do ...@@ -60,13 +60,13 @@ describe PipelinesFinder do
end end
end end
%w[running pending success failed canceled skipped].each do |target| HasStatus::AVAILABLE_STATUSES.each do |target|
context "when status is #{target}" do context "when status is #{target}" do
let(:params) { { status: target } } let(:params) { { status: target } }
let!(:pipeline) { create(:ci_pipeline, project: project, status: target) } let!(:pipeline) { create(:ci_pipeline, project: project, status: target) }
before do 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) create(:ci_pipeline, project: project, status: exception_status.sample)
end end
......
...@@ -95,11 +95,11 @@ describe API::Pipelines do ...@@ -95,11 +95,11 @@ describe API::Pipelines do
end end
end end
%w[running pending success failed canceled skipped].each do |target| HasStatus::AVAILABLE_STATUSES.each do |target|
context "when status is #{target}" do context "when status is #{target}" do
before do before do
create(:ci_pipeline, project: project, status: target) 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) create(:ci_pipeline, project: project, status: exception_status.sample)
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