diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-04-01 14:03:14 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-04-06 20:56:34 +0300 |
commit | b7fa7c4d59b2fbdc49db81aa2d6a2531c931a2fe (patch) | |
tree | 01b4f5e2aa9231049caa56196f09b4b8a6ebd406 /lib | |
parent | 88fc7ccddaab18435bdc85021d06d9aa21d28a68 (diff) |
Extend build status badge, add html/markdown methods
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/badge/build.rb | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/lib/gitlab/badge/build.rb b/lib/gitlab/badge/build.rb index 28a2391dbf8..e5e9fab3f5c 100644 --- a/lib/gitlab/badge/build.rb +++ b/lib/gitlab/badge/build.rb @@ -4,14 +4,15 @@ module Gitlab # Build badge # class Build + include Gitlab::Application.routes.url_helpers + include ActionView::Helpers::AssetTagHelper + include ActionView::Helpers::UrlHelper + def initialize(project, ref) + @project, @ref = project, ref @image = ::Ci::ImageForBuildService.new.execute(project, ref: ref) end - def to_s - @image[:name].sub(/\.svg$/, '') - end - def type 'image/svg+xml' end @@ -19,6 +20,27 @@ module Gitlab def data File.read(@image[:path]) end + + def to_s + @image[:name].sub(/\.svg$/, '') + end + + def to_html + link_to(image_tag(image_url, alt: 'build status'), link_url) + end + + def to_markdown + "[![build status](#{image_url})](#{link_url})" + end + + def image_url + build_namespace_project_badges_url(@project.namespace, + @project, @ref, format: :svg) + end + + def link_url + namespace_project_commits_url(@project.namespace, @project, id: @ref) + end end end end |