summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-02-05 14:22:58 +0100
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-02-11 10:29:14 +0100
commit28c4c949a5965f0328bb94d7ab1a318c9e226ff7 (patch)
tree8b2173f6151e6fee42639f2280af60a2f70d9835
parent14f928b73005300f419adb839cfd7bb06435abb8 (diff)
downloadgitlab-ce-28c4c949a5965f0328bb94d7ab1a318c9e226ff7.tar.gz
Improve CI status badge implementation
-rw-r--r--app/controllers/projects/commit_controller.rb5
-rw-r--r--app/services/ci/image_for_build_service.rb19
-rw-r--r--config/routes.rb4
3 files changed, 11 insertions, 17 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
diff --git a/config/routes.rb b/config/routes.rb
index 30e42e197f4..152a04061f2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -496,9 +496,9 @@ Rails.application.routes.draw do
get(
'/status/*id/badge',
- to: 'commit#status',
+ to: 'commit#badge',
constraints: { format: /png/ },
- as: :commit_status
+ as: :commit_badge
)
end