Introduce all_state_names so that we could avoid NOT IN

This commit is contained in:
Lin Jen-Shin 2016-10-05 00:10:23 +08:00
parent aafb0171e6
commit 5c9ac560e7
2 changed files with 6 additions and 2 deletions

View file

@ -32,8 +32,8 @@ class CommitStatus < ActiveRecord::Base
scope :exclude_ignored, -> do scope :exclude_ignored, -> do
quoted_when = connection.quote_column_name('when') quoted_when = connection.quote_column_name('when')
# We want to ignore failed_but_allowed jobs # We want to ignore failed_but_allowed jobs
where("allow_failure = ? OR status NOT IN (?)", where("allow_failure = ? OR status IN (?)",
false, [:failed, :canceled]). false, all_state_names - [:failed, :canceled]).
# We want to ignore skipped manual jobs # We want to ignore skipped manual jobs
where("#{quoted_when} <> ? OR status <> ?", 'manual', 'skipped'). where("#{quoted_when} <> ? OR status <> ?", 'manual', 'skipped').
# We want to ignore skipped on_failure # We want to ignore skipped on_failure

View file

@ -43,6 +43,10 @@ module HasStatus
def finished_at def finished_at
all.maximum(:finished_at) all.maximum(:finished_at)
end end
def all_state_names
state_machines.values.flat_map(&:states).flat_map { |s| s.map(&:name) }
end
end end
included do included do