diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-02-05 14:22:58 +0100 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-02-11 10:29:14 +0100 |
commit | 28c4c949a5965f0328bb94d7ab1a318c9e226ff7 (patch) | |
tree | 8b2173f6151e6fee42639f2280af60a2f70d9835 /app | |
parent | 14f928b73005300f419adb839cfd7bb06435abb8 (diff) | |
download | gitlab-ce-28c4c949a5965f0328bb94d7ab1a318c9e226ff7.tar.gz |
Improve CI status badge implementation
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/commit_controller.rb | 5 | ||||
-rw-r--r-- | app/services/ci/image_for_build_service.rb | 19 |
2 files changed, 9 insertions, 15 deletions
diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 637a911177c..36fef1740e2 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -57,9 +57,8 @@ class Projects::CommitController < Projects::ApplicationController render layout: false end - def status - status_sha = ci_commit.sha if ci_commit - image = Ci::ImageForBuildService.new.execute(@project, sha: status_sha) + def badge + image = Ci::ImageForBuildService.new.execute(@project, ref: params[:id]) send_file(image.path, filename: image.name, disposition: 'inline', type: 'image/svg+xml') end diff --git a/app/services/ci/image_for_build_service.rb b/app/services/ci/image_for_build_service.rb index f469b13e902..005a5c4661c 100644 --- a/app/services/ci/image_for_build_service.rb +++ b/app/services/ci/image_for_build_service.rb @@ -1,28 +1,23 @@ module Ci class ImageForBuildService - def execute(project, params) - sha = params[:sha] - sha ||= - if params[:ref] - project.commit(params[:ref]).try(:sha) - end + def execute(project, opts) + sha = opts[:sha] || ref_sha(project, opts[:ref]) commit = project.ci_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 - ) + OpenStruct.new(path: image_path, name: image_name) end private + def ref_sha(project, ref) + project.commit(ref).try(:sha) if ref + end + def image_for_commit(commit) return 'build-unknown.svg' unless commit - 'build-' + commit.status + ".svg" end end |