diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /lib/generators | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'lib/generators')
-rw-r--r-- | lib/generators/gitlab/usage_metric_definition_generator.rb | 27 | ||||
-rw-r--r-- | lib/generators/post_deployment_migration/post_deployment_migration_generator.rb | 14 |
2 files changed, 21 insertions, 20 deletions
diff --git a/lib/generators/gitlab/usage_metric_definition_generator.rb b/lib/generators/gitlab/usage_metric_definition_generator.rb index 2d65363bf7b..bd34ab0a16f 100644 --- a/lib/generators/gitlab/usage_metric_definition_generator.rb +++ b/lib/generators/gitlab/usage_metric_definition_generator.rb @@ -30,18 +30,20 @@ module Gitlab source_root File.expand_path('../../../generator_templates/usage_metric_definition', __dir__) - desc 'Generates a metric definition yml file' + desc 'Generates metric definitions yml files' class_option :ee, type: :boolean, optional: true, default: false, desc: 'Indicates if metric is for ee' class_option :dir, type: :string, desc: "Indicates the metric location. It must be one of: #{VALID_INPUT_DIRS.join(', ')}" - argument :key_path, type: :string, desc: 'Unique JSON key path for the metric' + argument :key_paths, type: :array, desc: 'Unique JSON key paths for the metrics' def create_metric_file validate! - template "metric_definition.yml", file_path + key_paths.each do |key_path| + template "metric_definition.yml", file_path(key_path), key_path + end end def time_frame @@ -66,12 +68,12 @@ module Gitlab private - def metric_name_suggestion + def metric_name_suggestion(key_path) "\nname: \"#{Usage::Metrics::NamesSuggestions::Generator.generate(key_path)}\"" end - def file_path - path = File.join(TOP_LEVEL_DIR, 'metrics', directory&.name, "#{file_name}.yml") + def file_path(key_path) + path = File.join(TOP_LEVEL_DIR, 'metrics', directory&.name, "#{file_name(key_path)}.yml") path = File.join(TOP_LEVEL_DIR_EE, path) if ee? path end @@ -79,7 +81,10 @@ module Gitlab 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? + + key_paths.each do |key_path| + raise "Metric definition with key path '#{key_path}' already exists" if metric_definition_exists?(key_path) + end end def ee? @@ -93,15 +98,15 @@ module Gitlab # Example of file name # # 20210201124931_g_project_management_issue_title_changed_weekly.yml - def file_name - "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{metric_name}" + def file_name(key_path) + "#{Time.now.utc.strftime("%Y%m%d%H%M%S")}_#{metric_name(key_path)}" end def directory @directory ||= TIME_FRAME_DIRS.find { |d| d.match?(input_dir) } end - def metric_name + def metric_name(key_path) key_path.split('.').last end @@ -109,7 +114,7 @@ module Gitlab @definitions ||= Gitlab::Usage::MetricDefinition.definitions(skip_validation: true) end - def metric_definition_exists? + def metric_definition_exists?(key_path) metric_definitions[key_path].present? end end diff --git a/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb b/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb index 66ee0e2440f..792c49a820d 100644 --- a/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb +++ b/lib/generators/post_deployment_migration/post_deployment_migration_generator.rb @@ -1,17 +1,13 @@ # frozen_string_literal: true require 'rails/generators' +require 'rails/generators/active_record' +require 'rails/generators/active_record/migration/migration_generator' module PostDeploymentMigration - class PostDeploymentMigrationGenerator < Rails::Generators::NamedBase - def create_migration_file - timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S') - - template "migration.rb", "db/post_migrate/#{timestamp}_#{file_name}.rb" - end - - def migration_class_name - file_name.camelize + class PostDeploymentMigrationGenerator < ActiveRecord::Generators::MigrationGenerator + def db_migrate_path + super.sub("migrate", "post_migrate") end end end |