Commit f19280fd authored by lauraMon's avatar lauraMon

Refactors finder a bit more

* Moves order_id_desc out of the Bridge and Build model and into
CommitStatus
parent 58a136e2
......@@ -15,15 +15,7 @@ module Ci
def execute
builds = init_collection.order_id_desc
if params[:scope].is_a?(Array)
unknown = params[:scope] - ::CommitStatus::AVAILABLE_STATUSES
raise ArgumentError, 'Scope contains invalid value(s)' unless unknown.empty?
builds.where(status: params[:scope]) # rubocop: disable CodeReuse/ActiveRecord
else
filter_by_scope(builds)
end
filter_by_scope(builds)
rescue Gitlab::Access::AccessDeniedError
type.none
end
......@@ -57,6 +49,8 @@ module Ci
end
def filter_by_scope(builds)
return filter_by_statuses!(params[:scope], builds) if params[:scope].is_a?(Array)
case params[:scope]
when 'pending'
builds.pending.reverse_order
......@@ -69,6 +63,13 @@ module Ci
end
end
def filter_by_statuses!(statuses, builds)
unknown_statuses = params[:scope] - ::CommitStatus::AVAILABLE_STATUSES
raise ArgumentError, 'Scope contains invalid value(s)' unless unknown_statuses.empty?
builds.where(status: params[:scope]) # rubocop: disable CodeReuse/ActiveRecord
end
def jobs_by_type(relation, type)
case type.name
when ::Ci::Build.name
......
......@@ -21,8 +21,6 @@ module Ci
validates :ref, presence: true
scope :order_id_desc, -> { order('ci_builds.id DESC') }
# rubocop:disable Cop/ActiveRecordSerialize
serialize :options
serialize :yaml_variables, ::Gitlab::Serializer::Ci::Variables
......
......@@ -175,7 +175,6 @@ module Ci
end
scope :queued_before, ->(time) { where(arel_table[:queued_at].lt(time)) }
scope :order_id_desc, -> { order('ci_builds.id DESC') }
scope :preload_project_and_pipeline_project, -> do
preload(Ci::Pipeline::PROJECT_ROUTE_AND_NAMESPACE_ROUTE,
......
......@@ -32,6 +32,8 @@ class CommitStatus < ApplicationRecord
where(allow_failure: true, status: [:failed, :canceled])
end
scope :order_id_desc, -> { order('ci_builds.id DESC') }
scope :exclude_ignored, -> do
# We want to ignore failed but allowed to fail jobs.
#
......
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