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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
1.8 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
2021-09-30 23:02:18 +05:30
include GlobalID::Identification
2017-08-17 22:00:37 +05:30
2020-04-22 19:07:51 +05:30
attr_reader :project, :stage, :name, :jobs
2017-08-17 22:00:37 +05:30
delegate :size, to: :jobs
2020-04-22 19:07:51 +05:30
def initialize(project, stage, name:, jobs:)
@project = project
2017-08-17 22:00:37 +05:30
@stage = stage
@name = name
@jobs = jobs
end
2021-09-30 23:02:18 +05:30
def id
"#{stage.id}-#{name}"
end
2021-04-29 21:17:54 +05:30
def ==(other)
other.present? && other.is_a?(self.class) &&
project == other.project &&
stage == other.stage &&
name == other.name
end
2017-08-17 22:00:37 +05:30
def status
2019-12-21 20:55:43 +05:30
strong_memoize(:status) do
2021-03-08 18:12:59 +05:30
status_struct.status
end
end
def success?
status.to_s == 'success'
end
def has_warnings?
status_struct.warnings?
end
def status_struct
strong_memoize(:status_struct) do
2020-10-24 23:57:45 +05:30
Gitlab::Ci::Status::Composite
2021-04-17 20:07:23 +05:30
.new(@jobs, project: project)
2019-12-21 20:55:43 +05:30
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
2021-03-08 18:12:59 +05:30
# Construct a grouping of statuses for this stage.
# We allow the caller to pass in statuses for efficiency (avoiding N+1
# queries).
def self.fabricate(project, stage, statuses = nil)
statuses ||= stage.latest_statuses
statuses
2018-11-08 19:23:39 +05:30
.sort_by(&:sortable_name).group_by(&:group_name)
.map do |group_name, grouped_statuses|
2020-04-22 19:07:51 +05:30
self.new(project, stage, name: group_name, jobs: grouped_statuses)
2018-11-08 19:23:39 +05:30
end
end
2017-08-17 22:00:37 +05:30
end
end