GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit 28c4c949 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Improve CI status badge implementation

parent 14f928b7
......@@ -57,9 +57,8 @@ def branches
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
......
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
......
......@@ -496,9 +496,9 @@
get(
'/status/*id/badge',
to: 'commit#status',
to: 'commit#badge',
constraints: { format: /png/ },
as: :commit_status
as: :commit_badge
)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment