Commit 69269efb authored by Grzegorz Bizon's avatar Grzegorz Bizon

Remove duplication between bridge and job only policies

parent 536eb638
...@@ -15,15 +15,6 @@ module EE ...@@ -15,15 +15,6 @@ module EE
ALLOWED_KEYS = %i[trigger stage allow_failure only except].freeze ALLOWED_KEYS = %i[trigger stage allow_failure only except].freeze
# TODO we probably need a common ancestor for a status / job
#
DEFAULT_ONLY_POLICY = {
refs: %w(branches tags)
}.freeze
DEFAULT_EXCEPT_POLICY = {
}.freeze
validations do validations do
validates :config, allowed_keys: ALLOWED_KEYS validates :config, allowed_keys: ALLOWED_KEYS
validates :config, presence: true validates :config, presence: true
...@@ -39,7 +30,8 @@ module EE ...@@ -39,7 +30,8 @@ module EE
description: 'Pipeline stage this job will be executed into.' description: 'Pipeline stage this job will be executed into.'
entry :only, ::Gitlab::Ci::Config::Entry::Policy, entry :only, ::Gitlab::Ci::Config::Entry::Policy,
description: 'Refs policy this job will be executed for.' description: 'Refs policy this job will be executed for.',
default: ::Gitlab::Ci::Config::Entry::Policy::DEFAULT_ONLY
entry :except, ::Gitlab::Ci::Config::Entry::Policy, entry :except, ::Gitlab::Ci::Config::Entry::Policy,
description: 'Refs policy this job will be executed for.' description: 'Refs policy this job will be executed for.'
...@@ -56,8 +48,8 @@ module EE ...@@ -56,8 +48,8 @@ module EE
trigger: trigger_value, trigger: trigger_value,
ignore: !!allow_failure, ignore: !!allow_failure,
stage: stage_value, stage: stage_value,
only: DEFAULT_ONLY_POLICY.deep_merge(only_value.to_h), only: only_value,
except: DEFAULT_EXCEPT_POLICY.deep_merge(except_value.to_h) } except: except_value }.compact
end end
end end
end end
......
...@@ -63,7 +63,6 @@ describe Gitlab::Ci::Config::Entry::Jobs do ...@@ -63,7 +63,6 @@ describe Gitlab::Ci::Config::Entry::Jobs do
trigger: { project: 'my/project' }, trigger: { project: 'my/project' },
stage: 'test', stage: 'test',
only: { refs: %w[branches tags] }, only: { refs: %w[branches tags] },
except: {},
ignore: false ignore: false
}, },
regular_job: { regular_job: {
...@@ -71,7 +70,6 @@ describe Gitlab::Ci::Config::Entry::Jobs do ...@@ -71,7 +70,6 @@ describe Gitlab::Ci::Config::Entry::Jobs do
name: :regular_job, name: :regular_job,
stage: 'test', stage: 'test',
only: { refs: %w[branches tags] }, only: { refs: %w[branches tags] },
except: {},
ignore: false ignore: false
}) })
end end
......
...@@ -67,7 +67,7 @@ module Gitlab ...@@ -67,7 +67,7 @@ module Gitlab
entry :only, Entry::Policy, entry :only, Entry::Policy,
description: 'Refs policy this job will be executed for.', description: 'Refs policy this job will be executed for.',
default: { refs: %w[branches tags] } default: Entry::Policy::DEFAULT_ONLY
entry :except, Entry::Policy, entry :except, Entry::Policy,
description: 'Refs policy this job will be executed for.' description: 'Refs policy this job will be executed for.'
......
...@@ -11,6 +11,8 @@ module Gitlab ...@@ -11,6 +11,8 @@ module Gitlab
strategy :RefsPolicy, if: -> (config) { config.is_a?(Array) } strategy :RefsPolicy, if: -> (config) { config.is_a?(Array) }
strategy :ComplexPolicy, if: -> (config) { config.is_a?(Hash) } strategy :ComplexPolicy, if: -> (config) { config.is_a?(Hash) }
DEFAULT_ONLY = { refs: %w[branches tags] }.freeze
class RefsPolicy < ::Gitlab::Config::Entry::Node class RefsPolicy < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable include ::Gitlab::Config::Entry::Validatable
......
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