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

74 lines
1.5 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
module Ci
# Currently this is artificial object, constructed dynamically
# We should migrate this object to actual database record in the future
class LegacyStage
include StaticModel
2020-01-01 13:55:28 +05:30
include Presentable
2017-09-10 17:25:29 +05:30
attr_reader :pipeline, :name
delegate :project, to: :pipeline
def initialize(pipeline, name:, status: nil, warnings: nil)
@pipeline = pipeline
@name = name
@status = status
2019-12-21 20:55:43 +05:30
# support ints and booleans
@has_warnings = ActiveRecord::Type::Boolean.new.cast(warnings)
2017-09-10 17:25:29 +05:30
end
def groups
2020-04-22 19:07:51 +05:30
@groups ||= Ci::Group.fabricate(project, self)
2017-09-10 17:25:29 +05:30
end
def to_param
name
end
def statuses_count
@statuses_count ||= statuses.count
end
def status
2020-04-22 19:07:51 +05:30
@status ||= statuses.latest.slow_composite_status(project: project)
2017-09-10 17:25:29 +05:30
end
def detailed_status(current_user)
Gitlab::Ci::Status::Stage::Factory
.new(self, current_user)
.fabricate!
end
2020-05-24 23:13:21 +05:30
def latest_statuses
statuses.ordered.latest
end
2017-09-10 17:25:29 +05:30
def statuses
@statuses ||= pipeline.statuses.where(stage: name)
end
def builds
@builds ||= pipeline.builds.where(stage: name)
end
def success?
status.to_s == 'success'
end
def has_warnings?
2019-12-21 20:55:43 +05:30
# lazilly calculate the warnings
if @has_warnings.nil?
@has_warnings = statuses.latest.failed_but_allowed.any?
2017-09-10 17:25:29 +05:30
end
2019-12-21 20:55:43 +05:30
@has_warnings
2017-09-10 17:25:29 +05:30
end
2019-07-31 22:56:46 +05:30
def manual_playable?
%[manual scheduled skipped].include?(status.to_s)
end
2017-09-10 17:25:29 +05:30
end
end