2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
module Ci
|
|
|
|
class PipelinePresenter < Gitlab::View::Presenter::Delegated
|
2018-10-15 14:42:47 +05:30
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
# 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
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
presents :pipeline
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
def failed_builds
|
|
|
|
return [] unless can?(current_user, :read_build, pipeline)
|
|
|
|
|
|
|
|
strong_memoize(:failed_builds) do
|
|
|
|
pipeline.builds.latest.failed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def failure_reason
|
|
|
|
return unless pipeline.failure_reason?
|
|
|
|
|
2018-12-23 12:14:25 +05:30
|
|
|
self.class.failure_reasons[pipeline.failure_reason.to_sym] ||
|
2018-03-17 18:26:18 +05:30
|
|
|
pipeline.failure_reason
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def status_title
|
|
|
|
if auto_canceled?
|
|
|
|
"Pipeline is redundant and is auto-canceled by Pipeline ##{auto_canceled_by_id}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|