gitlabhq/gitlab-ci

View on GitHub
app/services/image_for_build_service.rb

Summary

Maintainability
A
0 mins
Test Coverage
class ImageForBuildService
  def execute(project, params)
    image_name =
      if params[:sha]
        commit = project.commits.find_by(sha: params[:sha])
        image_for_commit(commit)
      elsif params[:ref]
        commit = project.last_commit_for_ref(params[:ref])
        image_for_commit(commit)
      else
        'build-unknown.svg'
      end

    image_path = Rails.root.join('public', 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