Read about our upcoming Code of Conduct on this issue

This instance will be upgraded to Heptapod 0.28.1 on 2022-01-26 at 16:00 UTC+1 (a few minutes of down time)

group.rb 1.27 KB
Newer Older
1
2
# frozen_string_literal: true

3
4
5
6
7
8
9
10
11
module Ci
  ##
  # 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.
  #
  class Group
    include StaticModel
12
    include Gitlab::Utils::StrongMemoize
13
14
15
16
17
18
19
20
21
22
23
24

    attr_reader :stage, :name, :jobs

    delegate :size, to: :jobs

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

    def status
25
26
27
28
29
30
31
32
33
34
35
      strong_memoize(:status) do
        if Feature.enabled?(:ci_composite_status, default_enabled: false)
          Gitlab::Ci::Status::Composite
            .new(@jobs)
            .status
        else
          CommitStatus
            .where(id: @jobs)
            .legacy_status
        end
      end
36
37
38
39
40
41
42
43
44
45
46
    end

    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

47
48
49
50
51
52
53
    def self.fabricate(stage)
      stage.statuses.ordered.latest
        .sort_by(&:sortable_name).group_by(&:group_name)
        .map do |group_name, grouped_statuses|
          self.new(stage, name: group_name, jobs: grouped_statuses)
        end
    end
54
55
  end
end