Welcome to mirror list, hosted at ThFree Co, Russian Federation.

image_for_build_service.rb « ci « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b8d241930351e5624e872c27910e41b2b9648ed2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module Ci
  class ImageForBuildService
    def execute(project, params)
      sha = params[:sha]
      sha ||=
        if params[:ref]
          project.gl_project.commit(params[:ref]).try(:sha)
        end

      commit = project.commits.ordered.find_by(sha: sha)
      image_name = image_for_commit(commit)

      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