diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-01-14 16:22:13 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-01-14 16:22:13 +0300 |
commit | 8b185467e4e9d1ef09143964b8a0f5fada2852f3 (patch) | |
tree | 8d2f6e9068f7cafed789c91ddb02661939eb3274 | |
parent | 3e9c9f97273efab6b623966597242811f8896024 (diff) |
Refactor only/except configuration policies
This commit refactors only/except policies so that these policies could
be self-contained. This also adds some changes to YAML configuration
library to provide more context to default entry value fabrication
process.
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 11 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/key.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/policy.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/retry.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/stage.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/stages.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/variables.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/config/entry/factory.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/config/entry/node.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/config/entry/simplifiable.rb | 5 |
10 files changed, 21 insertions, 21 deletions
diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 3239743bfff..5a810cc6436 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -16,13 +16,6 @@ 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 @@ -156,8 +149,8 @@ module Gitlab services: services_value, stage: stage_value, cache: cache_value, - only: DEFAULT_ONLY_POLICY.deep_merge(only_value.to_h), - except: DEFAULT_EXCEPT_POLICY.deep_merge(except_value.to_h), + only: only_value, + except: 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/key.rb b/lib/gitlab/ci/config/entry/key.rb index 0c10967e629..23d0dea0eb3 100644 --- a/lib/gitlab/ci/config/entry/key.rb +++ b/lib/gitlab/ci/config/entry/key.rb @@ -14,7 +14,7 @@ module Gitlab validates :config, key: true end - def self.default + def self.default(**) 'default' end end diff --git a/lib/gitlab/ci/config/entry/policy.rb b/lib/gitlab/ci/config/entry/policy.rb index 998da1f6837..fae6deede8b 100644 --- a/lib/gitlab/ci/config/entry/policy.rb +++ b/lib/gitlab/ci/config/entry/policy.rb @@ -64,7 +64,14 @@ module Gitlab end end - def self.default + def value + self.class.default(key: @key).yield_self do |default| + default.to_h.deep_merge(@subject.value.to_h) + end + end + + def self.default(**attributes) + { refs: %w(branches tags) } if attributes[:key] == :only end end end diff --git a/lib/gitlab/ci/config/entry/retry.rb b/lib/gitlab/ci/config/entry/retry.rb index eaf8b38aa3c..e9cbcb31e21 100644 --- a/lib/gitlab/ci/config/entry/retry.rb +++ b/lib/gitlab/ci/config/entry/retry.rb @@ -82,9 +82,6 @@ module Gitlab 'retry config' end end - - def self.default - end end end end diff --git a/lib/gitlab/ci/config/entry/stage.rb b/lib/gitlab/ci/config/entry/stage.rb index d6d576a3139..8c8494829d3 100644 --- a/lib/gitlab/ci/config/entry/stage.rb +++ b/lib/gitlab/ci/config/entry/stage.rb @@ -14,7 +14,7 @@ module Gitlab validates :config, type: String end - def self.default + def self.default(**) 'test' end end diff --git a/lib/gitlab/ci/config/entry/stages.rb b/lib/gitlab/ci/config/entry/stages.rb index 2d715cbc6bb..da91d57c2e7 100644 --- a/lib/gitlab/ci/config/entry/stages.rb +++ b/lib/gitlab/ci/config/entry/stages.rb @@ -14,7 +14,7 @@ module Gitlab validates :config, array_of_strings: true end - def self.default + def self.default(**) %w[build test deploy] end end diff --git a/lib/gitlab/ci/config/entry/variables.rb b/lib/gitlab/ci/config/entry/variables.rb index 89d790ebfa6..c9d0c7cb568 100644 --- a/lib/gitlab/ci/config/entry/variables.rb +++ b/lib/gitlab/ci/config/entry/variables.rb @@ -14,7 +14,7 @@ module Gitlab validates :config, variables: true end - def self.default + def self.default(**) {} end diff --git a/lib/gitlab/config/entry/factory.rb b/lib/gitlab/config/entry/factory.rb index 30d43c9f9a1..39edfa332b4 100644 --- a/lib/gitlab/config/entry/factory.rb +++ b/lib/gitlab/config/entry/factory.rb @@ -53,10 +53,10 @@ module Gitlab # If entry has a default value we fabricate concrete node # with default value. # - if @entry.default.nil? + if @entry.default(@attributes).nil? fabricate(Entry::Undefined) else - fabricate(@entry, @entry.default) + fabricate(@entry, @entry.default(@attributes)) end end diff --git a/lib/gitlab/config/entry/node.rb b/lib/gitlab/config/entry/node.rb index 30357b2c95b..fe05158a73c 100644 --- a/lib/gitlab/config/entry/node.rb +++ b/lib/gitlab/config/entry/node.rb @@ -85,7 +85,7 @@ module Gitlab "#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>" end - def self.default + def self.default(**) end def self.aspects diff --git a/lib/gitlab/config/entry/simplifiable.rb b/lib/gitlab/config/entry/simplifiable.rb index 3e148fe2e91..213a7c35f4b 100644 --- a/lib/gitlab/config/entry/simplifiable.rb +++ b/lib/gitlab/config/entry/simplifiable.rb @@ -17,7 +17,7 @@ module Gitlab entry = self.class.entry_class(strategy) - super(entry.new(config, metadata)) + super(@subject = entry.new(config, metadata)) end def self.strategy(name, **opts) @@ -37,6 +37,9 @@ module Gitlab self::UnknownStrategy end end + + def self.default(**) + end end end end |