Commit 6192ea53 authored by Lin Jen-Shin's avatar Lin Jen-Shin
parent 3a99e36e
......@@ -89,23 +89,19 @@ module Ci
end
end
scope :latest, -> do
# ref can't be HEAD or SHA, can only be branch/tag name
scope :latest, ->(ref = nil) do
max_id = unscope(:select).select("max(#{quoted_table_name}.id)")
where(id: max_id.group(:ref, :sha))
end
# ref can't be HEAD or SHA, can only be branch/tag name
scope :latest_for, ->(ref) do
if ref
where(ref: ref)
else
self
end.latest
end.where(id: max_id.group(:ref, :sha))
end
def self.latest_successful_for(ref)
success.latest_for(ref).first
success.latest(ref).first
end
def self.truncate_sha(sha)
......
......@@ -234,7 +234,7 @@ class Commit
return @statuses[ref] if @statuses.key?(ref)
@statuses[ref] = pipelines.latest_for(ref).status
@statuses[ref] = pipelines.latest(ref).status
end
def revert_branch_name
......
......@@ -5,7 +5,7 @@ module Ci
sha = opts[:sha] || ref_sha(project, ref)
pipelines = project.pipelines.where(sha: sha)
image_name = image_for_status(pipelines.latest_for(ref).status)
image_name = image_for_status(pipelines.latest(ref).status)
image_path = Rails.root.join('public/ci', image_name)
OpenStruct.new(path: image_path, name: image_name)
......
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