File: settings_sections.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (58 lines) | stat: -rw-r--r-- 2,106 bytes parent folder | download
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# frozen_string_literal: true

module Tooling
  module Danger
    module SettingsSections
      def check!
        return if helper.stable_branch?

        changed_code_files = helper.changed_files(/\.(haml|vue)$/)
        return if changed_code_files.empty?

        vc_regexp = /(SettingsBlockComponent|settings-block|SettingsSectionComponent|settings-section)/
        lines_with_matches = filter_changed_lines(changed_code_files, vc_regexp)
        return if lines_with_matches.empty?

        markdown(<<~MARKDOWN)
            ## Searchable setting sections

            Looks like you have edited the template of some settings section. Please check that all changed sections are still searchable:

            - If you created a new section, make sure to add it to either `lib/search/project_settings.rb` or `lib/search/group_settings.rb`, or in their counterparts in `ee/` if this section is only available behind a licensed feature.
            - If you removed a section, make sure to also remove it from the files above.
            - If you changed a section's id, please update it also in the files above.
            - If you just moved code around within the same page, there is nothing to do.
            - If you are unsure what to do, please reach out to ~"group::personal productivity".

        MARKDOWN

        lines_with_matches.each do |file, lines|
          markdown(<<~MARKDOWN)
              #### `#{file}`

              ```shell
              #{lines.join("\n")}
              ```

          MARKDOWN
        end
      end

      def filter_changed_lines(files, pattern)
        files_with_lines = {}
        files.each do |file|
          next if file.start_with?('spec/', 'ee/spec/', 'qa/',
            'app/views/admin', 'ee/app/views/admin',
            'app/views/profiles', 'ee/app/views/profiles')

          matching_changed_lines = helper.changed_lines(file).select { |line| line =~ pattern }
          next unless matching_changed_lines.any?

          files_with_lines[file] = matching_changed_lines
        end

        files_with_lines
      end
    end
  end
end