summaryrefslogtreecommitdiff
path: root/app/models/ci/group.rb
blob: 9d5c55b86c5332b7c4d00c3c7069a88726547218 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
module Ci
  # Currently this model is not persisted in the database, but derived from a
  # pipelines jobs. We might, but at the same time might not, persist this model
  # in the database later
  class Group
    include StaticModel

    attr_reader :stage, :name, :statuses

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

    def status
      @status ||= commit_statuses.status
    end

    def detailed_status(current_user)
      if size == 1
        statuses[0].detailed_status(current_user)
      else
        Gitlab::Ci::Status::Group::Factory.new(self, current_user).fabricate!
      end
    end

    def size
      statuses.size
    end

    private

    def commit_statuses
      @commit_statuses ||= CommitStatus.where(id: statuses.map(&:id))
    end
  end
end