2018-08-03 03:15:25 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-05-06 12:45:46 -04:00
|
|
|
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
|
2019-10-01 08:05:59 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
2017-05-06 12:45:46 -04:00
|
|
|
|
2020-04-08 08:09:42 -04:00
|
|
|
attr_reader :project, :stage, :name, :jobs
|
2017-05-06 12:45:46 -04:00
|
|
|
|
|
|
|
delegate :size, to: :jobs
|
|
|
|
|
2020-04-08 08:09:42 -04:00
|
|
|
def initialize(project, stage, name:, jobs:)
|
|
|
|
@project = project
|
2017-05-06 12:45:46 -04:00
|
|
|
@stage = stage
|
|
|
|
@name = name
|
|
|
|
@jobs = jobs
|
|
|
|
end
|
|
|
|
|
|
|
|
def status
|
2019-10-01 08:05:59 -04:00
|
|
|
strong_memoize(:status) do
|
2020-08-19 08:10:17 -04:00
|
|
|
Gitlab::Ci::Status::Composite
|
|
|
|
.new(@jobs)
|
|
|
|
.status
|
2019-10-01 08:05:59 -04:00
|
|
|
end
|
2017-05-06 12:45:46 -04:00
|
|
|
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
|
|
|
|
|
2020-04-08 08:09:42 -04:00
|
|
|
def self.fabricate(project, stage)
|
2020-05-14 14:08:06 -04:00
|
|
|
stage.latest_statuses
|
2018-05-23 04:37:01 -04:00
|
|
|
.sort_by(&:sortable_name).group_by(&:group_name)
|
|
|
|
.map do |group_name, grouped_statuses|
|
2020-04-08 08:09:42 -04:00
|
|
|
self.new(project, stage, name: group_name, jobs: grouped_statuses)
|
2018-05-23 04:37:01 -04:00
|
|
|
end
|
|
|
|
end
|
2017-05-06 12:45:46 -04:00
|
|
|
end
|
|
|
|
end
|