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 /lib/gitlab/ci | |
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.
Diffstat (limited to 'lib/gitlab/ci')
-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 |
7 files changed, 14 insertions, 17 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 |