gitlab-org--gitlab-foss/app/services/ci/image_for_build_service.rb

26 lines
630 B
Ruby
Raw Normal View History

2015-08-26 01:42:46 +00:00
module Ci
class ImageForBuildService
2016-02-05 13:22:58 +00:00
def execute(project, opts)
sha = opts[:sha] || ref_sha(project, opts[:ref])
2015-08-26 01:42:46 +00:00
pipelines = project.pipelines.where(sha: sha)
pipelines = pipelines.where(ref: opts[:ref]) if opts[:ref]
image_name = image_for_status(pipelines.status)
2015-08-26 01:42:46 +00:00
image_path = Rails.root.join('public/ci', image_name)
2016-02-05 13:22:58 +00:00
OpenStruct.new(path: image_path, name: image_name)
2015-08-26 01:42:46 +00:00
end
private
2016-02-05 13:22:58 +00:00
def ref_sha(project, ref)
project.commit(ref).try(:sha) if ref
end
2016-04-11 14:55:40 +00:00
def image_for_status(status)
status ||= 'unknown'
'build-' + status + ".svg"
2015-08-26 01:42:46 +00:00
end
end
end