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

required_stops.rb « danger « tooling - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 788be5d70e6368bbc81b4ca4fe428ad737b04c33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# frozen_string_literal: true

require_relative 'suggestor'

module Tooling
  module Danger
    module RequiredStops
      include ::Tooling::Danger::Suggestor

      MIGRATION_FILES_REGEX = %r{^db/(post_)?migrate}

      MIGRATION_FINALIZE_METHODS = %w[finalize_background_migration ensure_batched_background_migration_is_finished
        finalize_batched_background_migration].freeze
      MIGRATION_FINALIZE_REGEX = /^\+\s*(.*\.)?(#{MIGRATION_FINALIZE_METHODS.join('|')})[( ]/

      DOC_URL = "https://docs.gitlab.com/ee/development/database/required_stops.html"
      WARNING_COMMENT = <<~COMMENT.freeze
        Finalizing data migration might be time consuming and require a [required stop](#{DOC_URL}).
        Check the timings of the underlying data migration.
        If possible schedule finalization for the first minor version after the next required stop.
      COMMENT

      def add_comment_for_finalized_migrations
        migration_files.each do |filename|
          add_suggestion(
            filename: filename,
            regex: MIGRATION_FINALIZE_REGEX,
            comment_text: WARNING_COMMENT
          )
        end
      end

      private

      def migration_files
        helper.all_changed_files.grep(MIGRATION_FILES_REGEX)
      end
    end
  end
end