diff options
Diffstat (limited to 'tooling/danger/bulk_database_actions.rb')
-rw-r--r-- | tooling/danger/bulk_database_actions.rb | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/tooling/danger/bulk_database_actions.rb b/tooling/danger/bulk_database_actions.rb index 0f74e31cdde..7f3edaf7663 100644 --- a/tooling/danger/bulk_database_actions.rb +++ b/tooling/danger/bulk_database_actions.rb @@ -1,34 +1,25 @@ # frozen_string_literal: true -require_relative 'suggestor' +require_relative 'suggestion' module Tooling module Danger - module BulkDatabaseActions - include ::Tooling::Danger::Suggestor + class BulkDatabaseActions < Suggestion + MATCH = %r{\A\+\s+(\S*\.)?((update|upsert|delete|destroy)(_all)?)\b} + REPLACEMENT = nil + DOCUMENTATION_LINK = 'https://docs.gitlab.com/ee/development/database_review.html#preparation-when-using-bulk-update-operations' - BULK_UPDATE_METHODS_REGEX = /\.((update|delete|destroy)(_all)?)\b/ + SUGGESTION = <<~MESSAGE_MARKDOWN.freeze + When using `update`, `upsert`, `delete`, `update_all`, `upsert_all`, `delete_all` or `destroy_all` + you must include the full database query and query execution plan in the merge request description, + and request a ~database review. - DOCUMENTATION_LINK = 'https://docs.gitlab.com/ee/development/database_review.html#preparation-when-using-update-delete-update_all-and-destroy_all' - COMMENT_TEXT = - "When using `update`, `delete`, `update_all`, `delete_all` or `destroy_all` you must include the full " \ - "database query and query execution plan in the merge request description, and request a ~database review. " \ - "This comment can be ignored if the object is not an ActiveRecord class, since no database query " \ - "would be generated. For more information, see [Database Review documentation](#{DOCUMENTATION_LINK}).".freeze + This comment can be ignored if the object is not an ActiveRecord class, since no database query would be generated. - def add_comment_for_bulk_database_action_method_usage - changed_ruby_files.each do |filename| - add_suggestion( - filename: filename, - regex: BULK_UPDATE_METHODS_REGEX, - comment_text: COMMENT_TEXT - ) - end - end + ---- - def changed_ruby_files - helper.added_files.select { |f| f.end_with?('.rb') && !f.start_with?('spec/', 'ee/spec/', 'jh/spec/') } - end + For more information, see [Database Review documentation](#{DOCUMENTATION_LINK}). + MESSAGE_MARKDOWN end end end |