2018-08-03 07:15:25 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-05 13:17:42 +00:00
|
|
|
module Ci
|
2016-12-05 13:22:41 +00:00
|
|
|
# Currently this is artificial object, constructed dynamically
|
|
|
|
# We should migrate this object to actual database record in the future
|
2017-06-01 10:00:37 +00:00
|
|
|
class LegacyStage
|
2016-12-05 13:22:41 +00:00
|
|
|
include StaticModel
|
2016-12-05 13:17:42 +00:00
|
|
|
|
|
|
|
attr_reader :pipeline, :name
|
|
|
|
|
2016-12-05 13:28:02 +00:00
|
|
|
delegate :project, to: :pipeline
|
|
|
|
|
2017-01-18 10:07:12 +00:00
|
|
|
def initialize(pipeline, name:, status: nil, warnings: nil)
|
2016-12-07 18:30:14 +00:00
|
|
|
@pipeline = pipeline
|
|
|
|
@name = name
|
|
|
|
@status = status
|
2017-01-18 10:07:12 +00:00
|
|
|
@warnings = warnings
|
2016-12-05 13:17:42 +00:00
|
|
|
end
|
|
|
|
|
2017-05-06 16:45:46 +00:00
|
|
|
def groups
|
2018-05-23 08:37:01 +00:00
|
|
|
@groups ||= Ci::Group.fabricate(self)
|
2017-05-06 16:45:46 +00:00
|
|
|
end
|
|
|
|
|
2016-12-05 13:22:41 +00:00
|
|
|
def to_param
|
|
|
|
name
|
|
|
|
end
|
|
|
|
|
2016-12-20 10:00:56 +00:00
|
|
|
def statuses_count
|
|
|
|
@statuses_count ||= statuses.count
|
|
|
|
end
|
|
|
|
|
2016-12-05 13:17:42 +00:00
|
|
|
def status
|
|
|
|
@status ||= statuses.latest.status
|
|
|
|
end
|
|
|
|
|
2016-12-08 16:52:24 +00:00
|
|
|
def detailed_status(current_user)
|
2016-12-13 12:24:25 +00:00
|
|
|
Gitlab::Ci::Status::Stage::Factory
|
|
|
|
.new(self, current_user)
|
|
|
|
.fabricate!
|
2016-12-05 13:38:01 +00:00
|
|
|
end
|
|
|
|
|
2016-12-05 13:17:42 +00:00
|
|
|
def statuses
|
2016-12-05 13:47:35 +00:00
|
|
|
@statuses ||= pipeline.statuses.where(stage: name)
|
2016-12-05 13:17:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def builds
|
2016-12-05 13:47:35 +00:00
|
|
|
@builds ||= pipeline.builds.where(stage: name)
|
2016-12-05 13:17:42 +00:00
|
|
|
end
|
2017-01-09 11:22:19 +00:00
|
|
|
|
|
|
|
def success?
|
|
|
|
status.to_s == 'success'
|
|
|
|
end
|
|
|
|
|
|
|
|
def has_warnings?
|
2017-03-08 11:34:45 +00:00
|
|
|
if @warnings.is_a?(Integer)
|
2017-03-08 09:58:41 +00:00
|
|
|
@warnings > 0
|
2017-01-19 17:49:14 +00:00
|
|
|
else
|
2017-03-08 09:58:41 +00:00
|
|
|
statuses.latest.failed_but_allowed.any?
|
2017-01-19 17:49:14 +00:00
|
|
|
end
|
2017-01-09 11:22:19 +00:00
|
|
|
end
|
2016-12-05 13:17:42 +00:00
|
|
|
end
|
|
|
|
end
|