Consider the case where we don't specify ref for pipeline

This commit is contained in:
Lin Jen-Shin 2017-02-16 22:17:42 +08:00
parent d38fb942e1
commit 3750b06b8c

View file

@ -91,11 +91,13 @@ module Ci
scope :latest, ->(ref = nil) do
max_id = unscope(:select)
.select("max(#{quoted_table_name}.id)")
.where(ref: ref)
.group(:ref, :sha)
relation = ref ? where(ref: ref) : self
relation.where(id: max_id)
if ref
where(ref: ref, id: max_id.where(ref: ref))
else
where(id: max_id)
end
end
def self.latest_status(ref = nil)