2015-08-25 21:42:46 -04:00
|
|
|
module Ci
|
|
|
|
class ImageForBuildService
|
2016-02-05 08:22:58 -05:00
|
|
|
def execute(project, opts)
|
|
|
|
sha = opts[:sha] || ref_sha(project, opts[:ref])
|
2015-08-25 21:42:46 -04:00
|
|
|
|
2016-03-09 10:24:02 -05:00
|
|
|
commit = project.ci_commits.find_by(sha: sha)
|
2015-10-26 07:23:34 -04:00
|
|
|
image_name = image_for_commit(commit)
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
image_path = Rails.root.join('public/ci', image_name)
|
2016-02-05 08:22:58 -05:00
|
|
|
OpenStruct.new(path: image_path, name: image_name)
|
2015-08-25 21:42:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-02-05 08:22:58 -05:00
|
|
|
def ref_sha(project, ref)
|
|
|
|
project.commit(ref).try(:sha) if ref
|
|
|
|
end
|
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
def image_for_commit(commit)
|
|
|
|
return 'build-unknown.svg' unless commit
|
|
|
|
'build-' + commit.status + ".svg"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|