Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-10-27 00:10:31 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-10-27 00:10:31 +0300
commit277496b843d3c14cfd48286b1718b03775d83bbc (patch)
tree2ba3b900aa2103955dc28217d83acf9263ae08aa /rubocop
parentea413f31cf00268c71bfab1351b92f75e72c9a80 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r--rubocop/batched_background_migrations_dictionary.rb (renamed from rubocop/batched_background_migrations.rb)19
-rw-r--r--rubocop/cop/background_migration/dictionary_file.rb (renamed from rubocop/cop/background_migration/missing_dictionary_file.rb)31
-rw-r--r--rubocop/cop/migration/unfinished_dependencies.rb4
3 files changed, 44 insertions, 10 deletions
diff --git a/rubocop/batched_background_migrations.rb b/rubocop/batched_background_migrations_dictionary.rb
index ce7115e5cd5..286f0a57bad 100644
--- a/rubocop/batched_background_migrations.rb
+++ b/rubocop/batched_background_migrations_dictionary.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module RuboCop
- class BatchedBackgroundMigrations
+ class BatchedBackgroundMigrationsDictionary
DICTIONARY_BASE_DIR = 'db/docs/batched_background_migrations'
attr_reader :queued_migration_version
@@ -14,6 +14,7 @@ module RuboCop
next unless dictionary['queued_migration_version'].present?
data[dictionary['queued_migration_version'].to_s] = {
+ introduced_by_url: dictionary['introduced_by_url'],
finalize_after: dictionary['finalize_after'],
finalized_by: dictionary['finalized_by'].to_s
}
@@ -26,7 +27,21 @@ module RuboCop
end
def finalized_by
- self.class.dictionary_data.dig(queued_migration_version.to_s, :finalized_by)
+ dictionary_data&.dig(:finalized_by)
+ end
+
+ def finalize_after
+ dictionary_data&.dig(:finalize_after)
+ end
+
+ def introduced_by_url
+ dictionary_data&.dig(:introduced_by_url)
+ end
+
+ private
+
+ def dictionary_data
+ @dictionary_data ||= self.class.dictionary_data[queued_migration_version.to_s]
end
end
end
diff --git a/rubocop/cop/background_migration/missing_dictionary_file.rb b/rubocop/cop/background_migration/dictionary_file.rb
index 9158b268bf9..9ae47260e79 100644
--- a/rubocop/cop/background_migration/missing_dictionary_file.rb
+++ b/rubocop/cop/background_migration/dictionary_file.rb
@@ -1,17 +1,23 @@
# frozen_string_literal: true
require_relative '../../migration_helpers'
+require_relative '../../batched_background_migrations_dictionary'
module RuboCop
module Cop
module BackgroundMigration
# Checks the batched background migration has the corresponding dictionary file
- class MissingDictionaryFile < RuboCop::Cop::Base
+ class DictionaryFile < RuboCop::Cop::Base
include MigrationHelpers
- MSG = "Missing %{file_name}. " \
- "Use the generator 'batched_background_migration' to create dictionary files automatically. " \
- "For more details refer: https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#generator"
+ MSG = {
+ missing_key: "Mandatory key '%{key}' is missing from the dictionary. Please add with an appropriate value.",
+ missing_dictionary: <<-MESSAGE.delete("\n").squeeze(' ').strip
+ Missing %{file_name}.
+ Use the generator 'batched_background_migration' to create dictionary files automatically.
+ For more details refer: https://docs.gitlab.com/ee/development/database/batched_background_migrations.html#generator
+ MESSAGE
+ }.freeze
DICTIONARY_DIR = "db/docs/batched_background_migrations"
@@ -35,9 +41,10 @@ module RuboCop
migration_name_node.value
end
- return if dictionary_file?(migration_name)
+ error_code, msg_params = validate_dictionary_file(migration_name, node)
+ return unless error_code.present?
- add_offense(node, message: format(MSG, file_name: dictionary_file_path(migration_name)))
+ add_offense(node, message: format(MSG[error_code], msg_params))
end
private
@@ -50,6 +57,18 @@ module RuboCop
File.join(rails_root, DICTIONARY_DIR, "#{migration_class_name.underscore}.yml")
end
+ def validate_dictionary_file(migration_name, node)
+ unless dictionary_file?(migration_name)
+ return [:missing_dictionary, { file_name: dictionary_file_path(migration_name) }]
+ end
+
+ bbm_dictionary = RuboCop::BatchedBackgroundMigrationsDictionary.new(version(node))
+
+ return [:missing_key, { key: :finalize_after }] unless bbm_dictionary.finalize_after.present?
+
+ return [:missing_key, { key: :introduced_by_url }] unless bbm_dictionary.introduced_by_url.present?
+ end
+
def rails_root
@rails_root ||= File.expand_path('../../..', __dir__)
end
diff --git a/rubocop/cop/migration/unfinished_dependencies.rb b/rubocop/cop/migration/unfinished_dependencies.rb
index 1e0741c8411..56ba7d405c5 100644
--- a/rubocop/cop/migration/unfinished_dependencies.rb
+++ b/rubocop/cop/migration/unfinished_dependencies.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
require_relative '../../migration_helpers'
-require_relative '../../batched_background_migrations'
+require_relative '../../batched_background_migrations_dictionary'
module RuboCop
module Cop
@@ -43,7 +43,7 @@ module RuboCop
private
def fetch_finalized_by(queued_migration_version)
- BatchedBackgroundMigrations.new(queued_migration_version).finalized_by
+ BatchedBackgroundMigrationsDictionary.new(queued_migration_version).finalized_by
end
end
end