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-07-26 06:07:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-07-26 06:07:03 +0300
commitd7bf02e916cdc8ec926a35ced9cf6ab118e0f5cc (patch)
tree51ceaeda80a43b34806239834e1fb6c4b9336d22 /tooling
parentb8fcf7c3d6c3b48e59e6aae5b1a6b536bba8ac40 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'tooling')
-rw-r--r--tooling/danger/model_validations.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/tooling/danger/model_validations.rb b/tooling/danger/model_validations.rb
new file mode 100644
index 00000000000..4d7018753ff
--- /dev/null
+++ b/tooling/danger/model_validations.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+require_relative 'suggestor'
+
+module Tooling
+ module Danger
+ module ModelValidations
+ include ::Tooling::Danger::Suggestor
+
+ MODEL_FILES_REGEX = 'app/models'
+ EE_PREFIX = 'ee/'
+ VALIDATION_METHODS = %w[validates validate validates_each validates_with validates_associated].freeze
+ VALIDATIONS_REGEX = /^\+\s*(.*\.)?(#{VALIDATION_METHODS.join('|')})[( ]/
+
+ CODE_QUALITY_URL = "https://docs.gitlab.com/ee/development/code_review.html#quality"
+ SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT.freeze
+ Did you consider new validations can break existing records?
+ Please follow the [code quality guidelines about new model validations](#{CODE_QUALITY_URL}) when adding a new
+ model validation.
+
+ If you're adding the validations to a model with no records you can ignore this warning.
+ SUGGEST_COMMENT
+
+ def add_comment_for_added_validations
+ changed_model_files.each do |filename|
+ add_suggestion(
+ filename: filename,
+ regex: VALIDATIONS_REGEX,
+ comment_text: SUGGEST_MR_COMMENT
+ )
+ end
+ end
+
+ def changed_model_files
+ changed_files = helper.all_changed_files
+ ee_folder_prefix = "(#{EE_PREFIX})?"
+
+ changed_files.grep(%r{\A#{ee_folder_prefix}#{MODEL_FILES_REGEX}})
+ end
+ end
+ end
+end