2015-09-25 12:07:36 +05:30
|
|
|
module Ci
|
|
|
|
class ImageForBuildService
|
2016-04-02 18:10:28 +05:30
|
|
|
def execute(project, opts)
|
|
|
|
sha = opts[:sha] || ref_sha(project, opts[:ref])
|
2015-09-25 12:07:36 +05:30
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
pipelines = project.pipelines.where(sha: sha)
|
|
|
|
pipelines = pipelines.where(ref: opts[:ref]) if opts[:ref]
|
|
|
|
image_name = image_for_status(pipelines.status)
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
image_path = Rails.root.join('public/ci', image_name)
|
2016-04-02 18:10:28 +05:30
|
|
|
OpenStruct.new(path: image_path, name: image_name)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
def ref_sha(project, ref)
|
|
|
|
project.commit(ref).try(:sha) if ref
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
def image_for_status(status)
|
|
|
|
status ||= 'unknown'
|
|
|
|
'build-' + status + ".svg"
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|