Commit 8b185467 authored by Grzegorz Bizon's avatar Grzegorz Bizon

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.
parent 3e9c9f97
...@@ -16,13 +16,6 @@ module Gitlab ...@@ -16,13 +16,6 @@ module Gitlab
dependencies before_script after_script variables dependencies before_script after_script variables
environment coverage retry parallel extends].freeze environment coverage retry parallel extends].freeze
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
...@@ -156,8 +149,8 @@ module Gitlab ...@@ -156,8 +149,8 @@ module Gitlab
services: services_value, services: services_value,
stage: stage_value, stage: stage_value,
cache: cache_value, cache: cache_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.to_h,
variables: variables_defined? ? variables_value : nil, variables: variables_defined? ? variables_value : nil,
environment: environment_defined? ? environment_value : nil, environment: environment_defined? ? environment_value : nil,
environment_name: environment_defined? ? environment_value[:name] : nil, environment_name: environment_defined? ? environment_value[:name] : nil,
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
validates :config, key: true validates :config, key: true
end end
def self.default def self.default(**)
'default' 'default'
end end
end end
......
...@@ -64,7 +64,14 @@ module Gitlab ...@@ -64,7 +64,14 @@ module Gitlab
end end
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 end
end end
......
...@@ -82,9 +82,6 @@ module Gitlab ...@@ -82,9 +82,6 @@ module Gitlab
'retry config' 'retry config'
end end
end end
def self.default
end
end end
end end
end end
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
validates :config, type: String validates :config, type: String
end end
def self.default def self.default(**)
'test' 'test'
end end
end end
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
validates :config, array_of_strings: true validates :config, array_of_strings: true
end end
def self.default def self.default(**)
%w[build test deploy] %w[build test deploy]
end end
end end
......
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
validates :config, variables: true validates :config, variables: true
end end
def self.default def self.default(**)
{} {}
end end
......
...@@ -53,10 +53,10 @@ module Gitlab ...@@ -53,10 +53,10 @@ module Gitlab
# If entry has a default value we fabricate concrete node # If entry has a default value we fabricate concrete node
# with default value. # with default value.
# #
if @entry.default.nil? if @entry.default(@attributes).nil?
fabricate(Entry::Undefined) fabricate(Entry::Undefined)
else else
fabricate(@entry, @entry.default) fabricate(@entry, @entry.default(@attributes))
end end
end end
......
...@@ -85,7 +85,7 @@ module Gitlab ...@@ -85,7 +85,7 @@ module Gitlab
"#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>" "#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>"
end end
def self.default def self.default(**)
end end
def self.aspects def self.aspects
......
...@@ -17,7 +17,7 @@ module Gitlab ...@@ -17,7 +17,7 @@ module Gitlab
entry = self.class.entry_class(strategy) entry = self.class.entry_class(strategy)
super(entry.new(config, metadata)) super(@subject = entry.new(config, metadata))
end end
def self.strategy(name, **opts) def self.strategy(name, **opts)
...@@ -37,6 +37,9 @@ module Gitlab ...@@ -37,6 +37,9 @@ module Gitlab
self::UnknownStrategy self::UnknownStrategy
end end
end end
def self.default(**)
end
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