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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/ci/image_for_build_service.rb')
-rw-r--r--app/services/ci/image_for_build_service.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/app/services/ci/image_for_build_service.rb b/app/services/ci/image_for_build_service.rb
new file mode 100644
index 00000000000..b95835ba093
--- /dev/null
+++ b/app/services/ci/image_for_build_service.rb
@@ -0,0 +1,31 @@
+module Ci
+ 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/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