diff options
author | Grzegorz Bizon <grzegorz@gitlab.com> | 2018-12-13 13:39:55 +0300 |
---|---|---|
committer | GitLab Release Tools Bot <robert+release-tools@gitlab.com> | 2018-12-14 15:04:36 +0300 |
commit | e65afff444af6af3584f84684e0f54d6ca162c8d (patch) | |
tree | cb6298c3c70da25bda6427119f7b33c54b30aaee /lib | |
parent | 8e347203657630643cf24bfc501b35f0f9276943 (diff) |
Merge branch 're-define-default-only-except-policy' into 'master'
Re-define default only except policy
Closes #55099
See merge request gitlab-org/gitlab-ce!23765
(cherry picked from commit 42f45ed2d93baa5b2b2f2c51f5bd8527acf1df95)
7381f6a8 Revert "Define the default value for only/except policies"
74443274 Re-define a way how we define default only/except policy
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/config/entry/except_policy.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 15 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/only_policy.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/policy.rb | 15 |
4 files changed, 15 insertions, 50 deletions
diff --git a/lib/gitlab/ci/config/entry/except_policy.rb b/lib/gitlab/ci/config/entry/except_policy.rb deleted file mode 100644 index 46ded35325d..00000000000 --- a/lib/gitlab/ci/config/entry/except_policy.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Ci - class Config - module Entry - ## - # Entry that represents an only/except trigger policy for the job. - # - class ExceptPolicy < Policy - def self.default - end - end - end - end - end -end diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 085be5da08d..50942fbdb40 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -16,6 +16,13 @@ module Gitlab dependencies before_script after_script variables environment coverage retry parallel extends].freeze + DEFAULT_ONLY_POLICY = { + refs: %w(branches tags) + }.freeze + + DEFAULT_EXCEPT_POLICY = { + }.freeze + validations do validates :config, allowed_keys: ALLOWED_KEYS validates :config, presence: true @@ -65,10 +72,10 @@ module Gitlab entry :services, Entry::Services, description: 'Services that will be used to execute this job.' - entry :only, Entry::OnlyPolicy, + entry :only, Entry::Policy, description: 'Refs policy this job will be executed for.' - entry :except, Entry::ExceptPolicy, + entry :except, Entry::Policy, description: 'Refs policy this job will be executed for.' entry :variables, Entry::Variables, @@ -154,8 +161,8 @@ module Gitlab services: services_value, stage: stage_value, cache: cache_value, - only: only_value, - except: except_value, + only: DEFAULT_ONLY_POLICY.deep_merge(only_value.to_h), + except: DEFAULT_EXCEPT_POLICY.deep_merge(except_value.to_h), variables: variables_defined? ? variables_value : nil, environment: environment_defined? ? environment_value : nil, environment_name: environment_defined? ? environment_value[:name] : nil, diff --git a/lib/gitlab/ci/config/entry/only_policy.rb b/lib/gitlab/ci/config/entry/only_policy.rb deleted file mode 100644 index 9a581b8e97e..00000000000 --- a/lib/gitlab/ci/config/entry/only_policy.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module Ci - class Config - module Entry - ## - # Entry that represents an only/except trigger policy for the job. - # - class OnlyPolicy < Policy - def self.default - { refs: %w[branches tags] } - end - end - end - end - end -end diff --git a/lib/gitlab/ci/config/entry/policy.rb b/lib/gitlab/ci/config/entry/policy.rb index 81e74a639fc..998da1f6837 100644 --- a/lib/gitlab/ci/config/entry/policy.rb +++ b/lib/gitlab/ci/config/entry/policy.rb @@ -5,9 +5,12 @@ module Gitlab class Config module Entry ## - # Base class for OnlyPolicy and ExceptPolicy + # Entry that represents an only/except trigger policy for the job. # class Policy < ::Gitlab::Config::Entry::Simplifiable + strategy :RefsPolicy, if: -> (config) { config.is_a?(Array) } + strategy :ComplexPolicy, if: -> (config) { config.is_a?(Hash) } + class RefsPolicy < ::Gitlab::Config::Entry::Node include ::Gitlab::Config::Entry::Validatable @@ -63,16 +66,6 @@ module Gitlab def self.default end - - ## - # Class-level execution won't be inherited by subclasses by default. - # Therefore, we need to explicitly execute that for OnlyPolicy and ExceptPolicy - def self.inherited(klass) - super - - klass.strategy :RefsPolicy, if: -> (config) { config.is_a?(Array) } - klass.strategy :ComplexPolicy, if: -> (config) { config.is_a?(Hash) } - end end end end |