diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-01-14 19:27:13 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2019-01-15 13:18:14 +0300 |
commit | 7b712d359880cb15bad4c0f01308bf12b1518e60 (patch) | |
tree | bdeac924e9cb9bcc51daa0a52ed7274465f5148d /lib/gitlab | |
parent | 0cba9bef8a399e8f2003fee23fbda6f525921175 (diff) |
Make default config entry value configurable
Introduce `default:` configuration entry setting that makes it possible
to configure a default value of an entry, what overrides class-level
`def self.default` value.
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/key.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/policy.rb | 8 | ||||
-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/config/entry/configurable.rb | 1 | ||||
-rw-r--r-- | lib/gitlab/config/entry/factory.rb | 23 | ||||
-rw-r--r-- | lib/gitlab/config/entry/node.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/config/entry/simplifiable.rb | 2 |
9 files changed, 20 insertions, 25 deletions
diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 326f2df1ea7..1d8904f7b29 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -66,7 +66,8 @@ module Gitlab description: 'Services that will be used to execute this job.' 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] } entry :except, Entry::Policy, description: 'Refs policy this job will be executed for.' diff --git a/lib/gitlab/ci/config/entry/key.rb b/lib/gitlab/ci/config/entry/key.rb index 23d0dea0eb3..0c10967e629 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 bd571b8ea83..5195c4d87fe 100644 --- a/lib/gitlab/ci/config/entry/policy.rb +++ b/lib/gitlab/ci/config/entry/policy.rb @@ -65,13 +65,7 @@ module Gitlab end def value - self.class.default(key: @subject.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 + default.to_h.deep_merge(@subject.value.to_h) end end end diff --git a/lib/gitlab/ci/config/entry/stage.rb b/lib/gitlab/ci/config/entry/stage.rb index 8c8494829d3..d6d576a3139 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 da91d57c2e7..2d715cbc6bb 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/config/entry/configurable.rb b/lib/gitlab/config/entry/configurable.rb index afdb60b2cd5..37ba16dba25 100644 --- a/lib/gitlab/config/entry/configurable.rb +++ b/lib/gitlab/config/entry/configurable.rb @@ -56,6 +56,7 @@ module Gitlab def entry(key, entry, metadata) factory = ::Gitlab::Config::Entry::Factory.new(entry) .with(description: metadata[:description]) + .with(default: metadata[:default]) (@nodes ||= {}).merge!(key.to_sym => factory) end diff --git a/lib/gitlab/config/entry/factory.rb b/lib/gitlab/config/entry/factory.rb index 089a20dd324..79f9ff32514 100644 --- a/lib/gitlab/config/entry/factory.rb +++ b/lib/gitlab/config/entry/factory.rb @@ -12,7 +12,7 @@ module Gitlab def initialize(entry) @entry = entry @metadata = {} - @attributes = {} + @attributes = { default: entry.default } end def value(value) @@ -21,12 +21,12 @@ module Gitlab end def metadata(metadata) - @metadata.merge!(metadata) + @metadata.merge!(metadata.compact) self end def with(attributes) - @attributes.merge!(attributes) + @attributes.merge!(attributes.compact) self end @@ -38,9 +38,7 @@ module Gitlab # See issue #18775. # if @value.nil? - Entry::Unspecified.new( - fabricate_unspecified - ) + Entry::Unspecified.new(fabricate_unspecified) else fabricate(@entry, @value) end @@ -53,12 +51,12 @@ module Gitlab # If entry has a default value we fabricate concrete node # with default value. # - @entry.default(@attributes).yield_self do |default| - if default.nil? - fabricate(Entry::Undefined) - else - fabricate(@entry, default) - end + default = @attributes.fetch(:default) + + if default.nil? + fabricate(Entry::Undefined) + else + fabricate(@entry, default) end end @@ -66,6 +64,7 @@ module Gitlab entry.new(value, @metadata).tap do |node| node.key = @attributes[:key] node.parent = @attributes[:parent] + node.default = @attributes[:default] node.description = @attributes[:description] end end diff --git a/lib/gitlab/config/entry/node.rb b/lib/gitlab/config/entry/node.rb index fe05158a73c..9999ab4ff95 100644 --- a/lib/gitlab/config/entry/node.rb +++ b/lib/gitlab/config/entry/node.rb @@ -10,7 +10,7 @@ module Gitlab InvalidError = Class.new(StandardError) attr_reader :config, :metadata - attr_accessor :key, :parent, :description + attr_accessor :key, :parent, :default, :description def initialize(config, **metadata) @config = config diff --git a/lib/gitlab/config/entry/simplifiable.rb b/lib/gitlab/config/entry/simplifiable.rb index 213a7c35f4b..22a0b448230 100644 --- a/lib/gitlab/config/entry/simplifiable.rb +++ b/lib/gitlab/config/entry/simplifiable.rb @@ -38,7 +38,7 @@ module Gitlab end end - def self.default(**) + def self.default end end end |