gitlab-org--gitlab-foss/app/models/ci/stage.rb

57 lines
1.1 KiB
Ruby
Raw Normal View History

module Ci
# Currently this is artificial object, constructed dynamically
# We should migrate this object to actual database record in the future
class Stage
include StaticModel
attr_reader :pipeline, :name
2016-12-05 13:28:02 +00:00
delegate :project, to: :pipeline
def initialize(pipeline, name:, status: nil, warnings: nil)
2016-12-07 18:30:14 +00:00
@pipeline = pipeline
@name = name
@status = status
@warnings = warnings
end
def to_param
name
end
2016-12-20 10:00:56 +00:00
def statuses_count
@statuses_count ||= statuses.count
end
def status
@status ||= statuses.latest.status
end
def detailed_status(current_user)
Gitlab::Ci::Status::Stage::Factory
.new(self, current_user)
.fabricate!
2016-12-05 13:38:01 +00:00
end
def statuses
2016-12-05 13:47:35 +00:00
@statuses ||= pipeline.statuses.where(stage: name)
end
def builds
2016-12-05 13:47:35 +00:00
@builds ||= pipeline.builds.where(stage: name)
end
def success?
status.to_s == 'success'
end
def has_warnings?
if @warnings.nil?
statuses.latest.failed_but_allowed.any?
else
@warnings
end
end
end
end