summaryrefslogtreecommitdiff
path: root/lib/generators
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /lib/generators
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'lib/generators')
-rw-r--r--lib/generators/gitlab/usage_metric_definition_generator.rb28
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/generators/gitlab/usage_metric_definition_generator.rb b/lib/generators/gitlab/usage_metric_definition_generator.rb
index d3fac4c74f3..7a01050ed0c 100644
--- a/lib/generators/gitlab/usage_metric_definition_generator.rb
+++ b/lib/generators/gitlab/usage_metric_definition_generator.rb
@@ -18,6 +18,9 @@ module Gitlab
Directory.new('license', 'none', 'string')
].freeze
+ TOP_LEVEL_DIR = 'config'
+ TOP_LEVEL_DIR_EE = 'ee'
+
VALID_INPUT_DIRS = (TIME_FRAME_DIRS.flat_map { |d| [d.name, d.time_frame] } - %w(none)).freeze
source_root File.expand_path('../../../generator_templates/usage_metric_definition', __dir__)
@@ -56,15 +59,22 @@ module Gitlab
private
+ def metric_name_suggestion
+ return unless Feature.enabled?(:product_intelligence_metrics_names_suggestions, default_enabled: :yaml)
+
+ "\nname: #{Usage::Metrics::NamesSuggestions::Generator.generate(key_path)}"
+ end
+
def file_path
- path = File.join('config', 'metrics', directory&.name, "#{file_name}.yml")
- path = File.join('ee', path) if ee?
+ path = File.join(TOP_LEVEL_DIR, 'metrics', directory&.name, "#{file_name}.yml")
+ path = File.join(TOP_LEVEL_DIR_EE, path) if ee?
path
end
def validate!
raise "--dir option is required" unless input_dir.present?
raise "Invalid dir #{input_dir}, allowed options are #{VALID_INPUT_DIRS.join(', ')}" unless directory.present?
+ raise "Metric definition with key path '#{key_path}' already exists" if metric_definition_exists?
end
def ee?
@@ -79,11 +89,23 @@ module Gitlab
#
# 20210201124931_g_project_management_issue_title_changed_weekly.yml
def file_name
- "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{key_path.split('.').last}"
+ "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{metric_name}"
end
def directory
@directory ||= TIME_FRAME_DIRS.find { |d| d.match?(input_dir) }
end
+
+ def metric_name
+ key_path.split('.').last
+ end
+
+ def metric_definitions
+ @definitions ||= Gitlab::Usage::MetricDefinition.definitions
+ end
+
+ def metric_definition_exists?
+ metric_definitions[key_path].present?
+ end
end
end