Class: Ci::Group

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize, GlobalID::Identification, StaticModel
Defined in:
app/models/ci/group.rb

Overview

This domain model is a representation of a group of jobs that are related to each other, like ‘rspec 0 1`, `rspec 0 2`.

It is not persisted in the database.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from StaticModel

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

Constructor Details

#initialize(project, stage, name:, jobs:) ⇒ Group

Returns a new instance of Group.



19
20
21
22
23
24
# File 'app/models/ci/group.rb', line 19

def initialize(project, stage, name:, jobs:)
  @project = project
  @stage = stage
  @name = name
  @jobs = jobs
end

Instance Attribute Details

#jobsObject (readonly)

Returns the value of attribute jobs.



15
16
17
# File 'app/models/ci/group.rb', line 15

def jobs
  @jobs
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'app/models/ci/group.rb', line 15

def name
  @name
end

#projectObject (readonly)

Returns the value of attribute project.



15
16
17
# File 'app/models/ci/group.rb', line 15

def project
  @project
end

#stageObject (readonly)

Returns the value of attribute stage.



15
16
17
# File 'app/models/ci/group.rb', line 15

def stage
  @stage
end

Class Method Details

.fabricate(project, stage, statuses = nil) ⇒ Object

Construct a grouping of statuses for this stage. We allow the caller to pass in statuses for efficiency (avoiding N+1 queries).



69
70
71
72
73
74
75
76
77
# File 'app/models/ci/group.rb', line 69

def self.fabricate(project, stage, statuses = nil)
  statuses ||= stage.latest_statuses

  statuses
    .sort_by(&:sortable_name).group_by(&:group_name)
    .map do |group_name, grouped_statuses|
      self.new(project, stage, name: group_name, jobs: grouped_statuses)
    end
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
33
34
35
# File 'app/models/ci/group.rb', line 30

def ==(other)
  other.present? && other.is_a?(self.class) &&
    project == other.project &&
    stage == other.stage &&
    name == other.name
end

#detailed_status(current_user) ⇒ Object



57
58
59
60
61
62
63
64
# File 'app/models/ci/group.rb', line 57

def detailed_status(current_user)
  if jobs.one?
    jobs.first.detailed_status(current_user)
  else
    Gitlab::Ci::Status::Group::Factory
      .new(self, current_user).fabricate!
  end
end

#has_warnings?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'app/models/ci/group.rb', line 47

def has_warnings?
  status_struct.warnings?
end

#idObject



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

def id
  "#{stage.id}-#{name}"
end

#statusObject



37
38
39
40
41
# File 'app/models/ci/group.rb', line 37

def status
  strong_memoize(:status) do
    status_struct.status
  end
end

#status_structObject



51
52
53
54
55
# File 'app/models/ci/group.rb', line 51

def status_struct
  strong_memoize(:status_struct) do
    Gitlab::Ci::Status::Composite.new(@jobs)
  end
end

#success?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'app/models/ci/group.rb', line 43

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