Class: Gitlab::Badge::Pipeline::Status

Inherits:
Base
  • Object
show all
Defined in:
lib/gitlab/badge/pipeline/status.rb

Overview

Pipeline status badge

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, ref, opts: {}) ⇒ Status

Returns a new instance of Status.


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/badge/pipeline/status.rb', line 12

def initialize(project, ref, opts: {})
  @project = project
  @ref = ref
  @ignore_skipped = Gitlab::Utils.to_boolean(opts[:ignore_skipped], default: false)
  @customization = {
    key_width: opts[:key_width].to_i,
    key_text: opts[:key_text]
  }

  @sha = @project.commit(@ref).try(:sha)
end

Instance Attribute Details

#customizationObject (readonly)

Returns the value of attribute customization


10
11
12
# File 'lib/gitlab/badge/pipeline/status.rb', line 10

def customization
  @customization
end

#projectObject (readonly)

Returns the value of attribute project


10
11
12
# File 'lib/gitlab/badge/pipeline/status.rb', line 10

def project
  @project
end

#refObject (readonly)

Returns the value of attribute ref


10
11
12
# File 'lib/gitlab/badge/pipeline/status.rb', line 10

def ref
  @ref
end

Instance Method Details

#entityObject


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

def entity
  'pipeline'
end

#metadataObject

rubocop: enable CodeReuse/ActiveRecord


38
39
40
# File 'lib/gitlab/badge/pipeline/status.rb', line 38

def 
  @metadata ||= Pipeline::Metadata.new(self)
end

#statusObject

rubocop: disable CodeReuse/ActiveRecord


29
30
31
32
33
34
35
# File 'lib/gitlab/badge/pipeline/status.rb', line 29

def status
  pipelines = @project.ci_pipelines
    .where(sha: @sha)

  relation = @ignore_skipped ? pipelines.without_statuses([:skipped]) : pipelines
  relation.latest_status(@ref) || 'unknown'
end

#templateObject


42
43
44
# File 'lib/gitlab/badge/pipeline/status.rb', line 42

def template
  @template ||= Pipeline::Template.new(self)
end