diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-28 14:35:02 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-07-28 14:35:02 +0200 |
commit | 9ae1ecf876e40ce9dd64c72e025f32e38c882fd6 (patch) | |
tree | 8803b574cf48b2c8bc38e6fce295065d737bc730 /lib/gitlab/badge | |
parent | 42c035ee38a6629090da07aea818f4c9e3733075 (diff) | |
download | gitlab-ce-9ae1ecf876e40ce9dd64c72e025f32e38c882fd6.tar.gz |
Extract build status badge metadata to separate class
Diffstat (limited to 'lib/gitlab/badge')
-rw-r--r-- | lib/gitlab/badge/build.rb | 25 | ||||
-rw-r--r-- | lib/gitlab/badge/build/metadata.rb | 36 |
2 files changed, 40 insertions, 21 deletions
diff --git a/lib/gitlab/badge/build.rb b/lib/gitlab/badge/build.rb index e5e9fab3f5c..21d60854bf5 100644 --- a/lib/gitlab/badge/build.rb +++ b/lib/gitlab/badge/build.rb @@ -4,15 +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 metadata + Build::Metadata.new(@project, @ref) + end + def type 'image/svg+xml' end @@ -24,23 +24,6 @@ module Gitlab 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 diff --git a/lib/gitlab/badge/build/metadata.rb b/lib/gitlab/badge/build/metadata.rb new file mode 100644 index 00000000000..553ef8d7b16 --- /dev/null +++ b/lib/gitlab/badge/build/metadata.rb @@ -0,0 +1,36 @@ +module Gitlab + module Badge + class Build + ## + # Class that describes build badge metadata + # + class Metadata + include Gitlab::Application.routes.url_helpers + include ActionView::Helpers::AssetTagHelper + include ActionView::Helpers::UrlHelper + + def initialize(project, ref) + @project = project + @ref = ref + 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 +end |