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

38 lines
753 B
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
2016-12-05 13:47:35 +00:00
def initialize(pipeline, name:, status: nil)
2016-12-07 18:30:14 +00:00
@pipeline = pipeline
@name = name
@status = status
end
def to_param
name
end
def status
@status ||= statuses.latest.status
end
2016-12-05 13:38:01 +00:00
def detailed_status
Gitlab::Ci::Status::Stage::Factory.new(self).fabricate!
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
end
end