debian-mirror-gitlab/app/models/ci/group.rb

56 lines
1.3 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
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-12-21 20:55:43 +05:30
include Gitlab::Utils::StrongMemoize
2017-08-17 22:00:37 +05:30
attr_reader :stage, :name, :jobs
delegate :size, to: :jobs
def initialize(stage, name:, jobs:)
@stage = stage
@name = name
@jobs = jobs
end
def status
2019-12-21 20:55:43 +05:30
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
2017-08-17 22:00:37 +05:30
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
2018-11-08 19:23:39 +05:30
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
2017-08-17 22:00:37 +05:30
end
end