2015-09-25 12:07:36 +05:30
|
|
|
module Ci
|
|
|
|
class ImageForBuildService
|
|
|
|
def execute(project, params)
|
2015-11-26 14:37:03 +05:30
|
|
|
sha = params[:sha]
|
|
|
|
sha ||=
|
|
|
|
if params[:ref]
|
|
|
|
project.gl_project.commit(params[:ref]).try(:sha)
|
2015-09-25 12:07:36 +05:30
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
commit = project.commits.ordered.find_by(sha: sha)
|
|
|
|
image_name = image_for_commit(commit)
|
|
|
|
|
2015-09-25 12:07:36 +05:30
|
|
|
image_path = Rails.root.join('public/ci', image_name)
|
|
|
|
|
|
|
|
OpenStruct.new(
|
|
|
|
path: image_path,
|
|
|
|
name: image_name
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def image_for_commit(commit)
|
|
|
|
return 'build-unknown.svg' unless commit
|
|
|
|
|
|
|
|
'build-' + commit.status + ".svg"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|