2018-07-24 06:00:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-20 18:05:52 -04:00
|
|
|
module Ci
|
2017-03-28 13:47:11 -04:00
|
|
|
class PipelinePresenter < Gitlab::View::Presenter::Delegated
|
2018-04-21 18:30:37 -04:00
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2018-11-13 11:29:14 -05:00
|
|
|
# We use a class method here instead of a constant, allowing EE to redefine
|
|
|
|
# the returned `Hash` more easily.
|
|
|
|
def self.failure_reasons
|
|
|
|
{ config_error: 'CI/CD YAML configuration error!' }
|
|
|
|
end
|
2017-10-03 07:18:59 -04:00
|
|
|
|
|
|
|
presents :pipeline
|
2017-09-29 05:14:00 -04:00
|
|
|
|
2018-04-21 18:30:37 -04:00
|
|
|
def failed_builds
|
|
|
|
return [] unless can?(current_user, :read_build, pipeline)
|
|
|
|
|
|
|
|
strong_memoize(:failed_builds) do
|
|
|
|
pipeline.builds.latest.failed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-29 05:14:00 -04:00
|
|
|
def failure_reason
|
|
|
|
return unless pipeline.failure_reason?
|
|
|
|
|
2018-11-13 11:29:14 -05:00
|
|
|
self.class.failure_reasons[pipeline.failure_reason.to_sym] ||
|
2017-09-29 05:14:00 -04:00
|
|
|
pipeline.failure_reason
|
|
|
|
end
|
2017-03-20 18:05:52 -04:00
|
|
|
|
|
|
|
def status_title
|
2017-04-06 09:32:56 -04:00
|
|
|
if auto_canceled?
|
|
|
|
"Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}"
|
|
|
|
end
|
2017-03-20 18:05:52 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|