diff options
Diffstat (limited to 'lib/gitlab/config')
-rw-r--r-- | lib/gitlab/config/entry/configurable.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/config/entry/factory.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/config/entry/node.rb | 20 |
3 files changed, 26 insertions, 2 deletions
diff --git a/lib/gitlab/config/entry/configurable.rb b/lib/gitlab/config/entry/configurable.rb index 6bf77ebaa5b..aa6c724c2a3 100644 --- a/lib/gitlab/config/entry/configurable.rb +++ b/lib/gitlab/config/entry/configurable.rb @@ -76,7 +76,7 @@ module Gitlab private # rubocop: disable CodeReuse/ActiveRecord - def entry(key, entry, description: nil, default: nil, inherit: nil, reserved: nil, metadata: {}) + def entry(key, entry, description: nil, default: nil, inherit: nil, reserved: nil, deprecation: nil, metadata: {}) entry_name = key.to_sym raise ArgumentError, "Entry '#{key}' already defined in '#{name}'" if @nodes.to_h[entry_name] @@ -85,6 +85,7 @@ module Gitlab .with(default: default) .with(inherit: inherit) .with(reserved: reserved) + .with(deprecation: deprecation) .metadata(metadata) @nodes ||= {} diff --git a/lib/gitlab/config/entry/factory.rb b/lib/gitlab/config/entry/factory.rb index f76c98f7cbf..61f2071b62f 100644 --- a/lib/gitlab/config/entry/factory.rb +++ b/lib/gitlab/config/entry/factory.rb @@ -32,6 +32,10 @@ module Gitlab self end + def deprecation + @attributes[:deprecation] + end + def description @attributes[:description] end @@ -84,6 +88,7 @@ module Gitlab node.parent = @attributes[:parent] node.default = @attributes[:default] node.description = @attributes[:description] + node.deprecation = @attributes[:deprecation] end end end diff --git a/lib/gitlab/config/entry/node.rb b/lib/gitlab/config/entry/node.rb index 32912cb1046..6ce7046262b 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, :default, :description + attr_accessor :key, :parent, :default, :description, :deprecation def initialize(config, **metadata) @config = config @@ -128,6 +128,24 @@ module Gitlab private attr_reader :entries + + def log_and_warn_deprecated_entry(entry) + user = metadata[:user] + project = metadata[:project] + + if project && user + Gitlab::AppJsonLogger.info(event: 'ci_used_deprecated_keyword', + entry: entry.key.to_s, + user_id: user.id, + project_id: project.id) + end + + deprecation = entry.deprecation + add_warning( + "`#{entry.key}` is deprecated in " \ + "#{deprecation[:deprecated]} and will be removed in #{deprecation[:removed]}." + ) + end end end end |