Class: Ci::LegacyStage

Inherits:
Object
  • Object
show all
Includes:
Presentable, StaticModel
Defined in:
app/models/ci/legacy_stage.rb

Overview

Currently this is artificial object, constructed dynamically We should migrate this object to actual database record in the future

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Presentable

#present

Methods included from StaticModel

#==, #[], #destroyed?, #new_record?, #persisted?

Constructor Details

#initialize(pipeline, name:, status: nil, warnings: nil) ⇒ LegacyStage

Returns a new instance of LegacyStage.


14
15
16
17
18
19
20
# File 'app/models/ci/legacy_stage.rb', line 14

def initialize(pipeline, name:, status: nil, warnings: nil)
  @pipeline = pipeline
  @name = name
  @status = status
  # support ints and booleans
  @has_warnings = ActiveRecord::Type::Boolean.new.cast(warnings)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name


10
11
12
# File 'app/models/ci/legacy_stage.rb', line 10

def name
  @name
end

#pipelineObject (readonly)

Returns the value of attribute pipeline


10
11
12
# File 'app/models/ci/legacy_stage.rb', line 10

def pipeline
  @pipeline
end

Instance Method Details

#buildsObject


52
53
54
# File 'app/models/ci/legacy_stage.rb', line 52

def builds
  @builds ||= pipeline.builds.where(stage: name)
end

#detailed_status(current_user) ⇒ Object


38
39
40
41
42
# File 'app/models/ci/legacy_stage.rb', line 38

def detailed_status(current_user)
  Gitlab::Ci::Status::Stage::Factory
    .new(self, current_user)
    .fabricate!
end

#groupsObject


22
23
24
# File 'app/models/ci/legacy_stage.rb', line 22

def groups
  @groups ||= Ci::Group.fabricate(project, self)
end

#has_warnings?Boolean

Returns:

  • (Boolean)

60
61
62
63
64
65
66
67
# File 'app/models/ci/legacy_stage.rb', line 60

def has_warnings?
  # lazilly calculate the warnings
  if @has_warnings.nil?
    @has_warnings = statuses.latest.failed_but_allowed.any?
  end

  @has_warnings
end

#latest_statusesObject


44
45
46
# File 'app/models/ci/legacy_stage.rb', line 44

def latest_statuses
  statuses.ordered.latest
end

#manual_playable?Boolean

Returns:

  • (Boolean)

69
70
71
# File 'app/models/ci/legacy_stage.rb', line 69

def manual_playable?
  %[manual scheduled skipped].include?(status.to_s)
end

#statusObject


34
35
36
# File 'app/models/ci/legacy_stage.rb', line 34

def status
  @status ||= statuses.latest.composite_status
end

#statusesObject


48
49
50
# File 'app/models/ci/legacy_stage.rb', line 48

def statuses
  @statuses ||= pipeline.statuses.where(stage: name)
end

#statuses_countObject


30
31
32
# File 'app/models/ci/legacy_stage.rb', line 30

def statuses_count
  @statuses_count ||= statuses.count
end

#success?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'app/models/ci/legacy_stage.rb', line 56

def success?
  status.to_s == 'success'
end

#to_paramObject


26
27
28
# File 'app/models/ci/legacy_stage.rb', line 26

def to_param
  name
end