Class: Gitlab::Badge::Build

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::AssetTagHelper, ActionView::Helpers::UrlHelper
Defined in:
lib/gitlab/badge/build.rb

Overview

Build badge

Instance Method Summary collapse

Constructor Details

#initialize(project, ref) ⇒ Build

Returns a new instance of Build


11
12
13
14
# File 'lib/gitlab/badge/build.rb', line 11

def initialize(project, ref)
  @project, @ref = project, ref
  @image = ::Ci::ImageForBuildService.new.execute(project, ref: ref)
end

Instance Method Details

#dataObject


20
21
22
# File 'lib/gitlab/badge/build.rb', line 20

def data
  File.read(@image[:path])
end

#image_urlObject


36
37
38
39
# File 'lib/gitlab/badge/build.rb', line 36

def image_url
  build_namespace_project_badges_url(@project.namespace,
                                     @project, @ref, format: :svg)
end

41
42
43
# File 'lib/gitlab/badge/build.rb', line 41

def link_url
  namespace_project_commits_url(@project.namespace, @project, id: @ref)
end

#to_htmlObject


28
29
30
# File 'lib/gitlab/badge/build.rb', line 28

def to_html
  link_to(image_tag(image_url, alt: 'build status'), link_url)
end

#to_markdownObject


32
33
34
# File 'lib/gitlab/badge/build.rb', line 32

def to_markdown
  "[![build status](#{image_url})](#{link_url})"
end

#to_sObject


24
25
26
# File 'lib/gitlab/badge/build.rb', line 24

def to_s
  @image[:name].sub(/\.svg$/, '')
end

#typeObject


16
17
18
# File 'lib/gitlab/badge/build.rb', line 16

def type
  'image/svg+xml'
end