Commit 65bc55ee authored by Mayra Cabrera's avatar Mayra Cabrera

Use class method + private constant to override CE constants on EE

modules

Overrides constants on CommitStatusPresenter and
GitLab::Ci::Status::Build::Failed.

Closes #7204
parent 4babd252
# frozen_string_literal: true # frozen_string_literal: true
class CommitStatusPresenter < Gitlab::View::Presenter::Delegated class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
prepend ::EE::CommitStatusPresenter
CALLOUT_FAILURE_MESSAGES = { CALLOUT_FAILURE_MESSAGES = {
unknown_failure: 'There is an unknown failure, please try again', unknown_failure: 'There is an unknown failure, please try again',
script_failure: nil, script_failure: nil,
...@@ -10,12 +8,19 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated ...@@ -10,12 +8,19 @@ class CommitStatusPresenter < Gitlab::View::Presenter::Delegated
runner_system_failure: 'There has been a runner system failure, please try again', runner_system_failure: 'There has been a runner system failure, please try again',
missing_dependency_failure: 'There has been a missing dependency failure', missing_dependency_failure: 'There has been a missing dependency failure',
runner_unsupported: 'Your runner is outdated, please upgrade your runner' runner_unsupported: 'Your runner is outdated, please upgrade your runner'
}.merge(EE_CALLOUT_FAILURE_MESSAGES).freeze }.freeze
private_constant :CALLOUT_FAILURE_MESSAGES
presents :build presents :build
prepend ::EE::CommitStatusPresenter
def self.callout_failure_messages
CALLOUT_FAILURE_MESSAGES
end
def callout_failure_message def callout_failure_message
CALLOUT_FAILURE_MESSAGES.fetch(failure_reason.to_sym) self.class.callout_failure_messages.fetch(failure_reason.to_sym)
end end
def recoverable? def recoverable?
......
# frozen_string_literal: true # frozen_string_literal: true
module EE module EE
module CommitStatusPresenter module CommitStatusPresenter
EE_CALLOUT_FAILURE_MESSAGES = { extend ActiveSupport::Concern
protected_environment_failure: 'The environment this job is deploying to is protected. Only users with permission may successfully run this job'
}.freeze prepended do
EE_CALLOUT_FAILURE_MESSAGES = const_get(:CALLOUT_FAILURE_MESSAGES).merge(
protected_environment_failure: 'The environment this job is deploying to is protected. Only users with permission may successfully run this job'
).freeze
EE::CommitStatusPresenter.private_constant :EE_CALLOUT_FAILURE_MESSAGES
end
class_methods do
def callout_failure_messages
EE_CALLOUT_FAILURE_MESSAGES
end
end
end end
end end
...@@ -5,9 +5,21 @@ module EE ...@@ -5,9 +5,21 @@ module EE
module Status module Status
module Build module Build
module Failed module Failed
EE_REASONS = { extend ActiveSupport::Concern
protected_environment_failure: 'protected environment failure'
}.freeze prepended do
EE_REASONS = const_get(:REASONS).merge(
protected_environment_failure: 'protected environment failure'
).freeze
EE::Gitlab::Ci::Status::Build::Failed.private_constant :EE_REASONS
end
class_methods do
def reasons
EE_REASONS
end
end
end end
end end
end end
......
...@@ -3,8 +3,6 @@ module Gitlab ...@@ -3,8 +3,6 @@ module Gitlab
module Status module Status
module Build module Build
class Failed < Status::Extended class Failed < Status::Extended
prepend ::EE::Gitlab::Ci::Status::Build::Failed
REASONS = { REASONS = {
unknown_failure: 'unknown failure', unknown_failure: 'unknown failure',
script_failure: 'script failure', script_failure: 'script failure',
...@@ -13,7 +11,10 @@ module Gitlab ...@@ -13,7 +11,10 @@ module Gitlab
runner_system_failure: 'runner system failure', runner_system_failure: 'runner system failure',
missing_dependency_failure: 'missing dependency failure', missing_dependency_failure: 'missing dependency failure',
runner_unsupported: 'unsupported runner' runner_unsupported: 'unsupported runner'
}.merge(EE_REASONS).freeze }.freeze
private_constant :REASONS
prepend ::EE::Gitlab::Ci::Status::Build::Failed
def status_tooltip def status_tooltip
base_message base_message
...@@ -27,6 +28,10 @@ module Gitlab ...@@ -27,6 +28,10 @@ module Gitlab
build.failed? build.failed?
end end
def self.reasons
REASONS
end
private private
def base_message def base_message
...@@ -38,7 +43,7 @@ module Gitlab ...@@ -38,7 +43,7 @@ module Gitlab
end end
def failure_reason_message def failure_reason_message
REASONS.fetch(subject.failure_reason.to_sym) self.class.reasons.fetch(subject.failure_reason.to_sym)
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment