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-01-18 22:00:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-01-18 22:00:14 +0300
commit05f0ebba3a2c8ddf39e436f412dc2ab5bf1353b2 (patch)
tree11d0f2a6ec31c7793c184106cedc2ded3d9a2cc5 /tooling
parentec73467c23693d0db63a797d10194da9e72a74af (diff)
Add latest changes from gitlab-org/gitlab@15-8-stable-eev15.8.0-rc42
Diffstat (limited to 'tooling')
-rwxr-xr-xtooling/bin/view_to_js_mappings10
-rw-r--r--tooling/danger/config_files.rb2
-rw-r--r--tooling/danger/specs.rb31
-rw-r--r--tooling/danger/user_types.rb31
-rw-r--r--tooling/lib/tooling/view_to_js_mappings.rb77
-rw-r--r--tooling/quality/test_level.rb21
6 files changed, 116 insertions, 56 deletions
diff --git a/tooling/bin/view_to_js_mappings b/tooling/bin/view_to_js_mappings
new file mode 100755
index 00000000000..2cebb91892e
--- /dev/null
+++ b/tooling/bin/view_to_js_mappings
@@ -0,0 +1,10 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require_relative '../lib/tooling/view_to_js_mappings'
+
+changes = ARGV.shift
+output_file = ARGV.shift
+changed_files = File.read(changes).split(' ')
+
+File.write(output_file, Tooling::ViewToJsMappings.new.execute(changed_files).join(' '))
diff --git a/tooling/danger/config_files.rb b/tooling/danger/config_files.rb
index 436335bfc06..914605a3783 100644
--- a/tooling/danger/config_files.rb
+++ b/tooling/danger/config_files.rb
@@ -7,7 +7,7 @@ module Tooling
module ConfigFiles
SUGGEST_INTRODUCED_BY_COMMENT = <<~SUGGEST_COMMENT
```suggestion
- introduced_by_url: "%<url>s"
+ introduced_by_url: %<url>
```
SUGGEST_COMMENT
diff --git a/tooling/danger/specs.rb b/tooling/danger/specs.rb
index c7baf920314..6c0459a4344 100644
--- a/tooling/danger/specs.rb
+++ b/tooling/danger/specs.rb
@@ -45,12 +45,12 @@ module Tooling
for background information and alternative options.
SUGGEST_COMMENT
- FEATURE_CATEGORY_REGEX = /^\+.?RSpec\.describe(.+)(?!feature_category)/.freeze
+ RSPEC_TOP_LEVEL_DESCRIBE_REGEX = /^\+.?RSpec\.describe(.+)/.freeze
FEATURE_CATEGORY_SUGGESTION = <<~SUGGESTION_MARKDOWN
Consider adding `feature_category: <feature_category_name>` for this example if it is not set already.
See [testing best practices](https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#feature-category-metadata).
SUGGESTION_MARKDOWN
- FEATURE_CATEGORY_EXCLUDE = 'feature_category'
+ FEATURE_CATEGORY_KEYWORD = 'feature_category'
def changed_specs_files(ee: :include)
changed_files = helper.all_changed_files
@@ -86,13 +86,26 @@ module Tooling
end
def add_suggestions_for_feature_category(filename)
- add_suggestion(
- filename,
- FEATURE_CATEGORY_REGEX,
- FEATURE_CATEGORY_SUGGESTION,
- nil,
- FEATURE_CATEGORY_EXCLUDE
- )
+ file_lines = project_helper.file_lines(filename)
+ changed_lines = helper.changed_lines(filename)
+
+ changed_lines.each_with_index do |changed_line, i|
+ next unless changed_line =~ RSPEC_TOP_LEVEL_DESCRIBE_REGEX
+
+ next_line_in_file = file_lines[file_lines.find_index(changed_line.delete_prefix('+')) + 1]
+
+ if changed_line.include?(FEATURE_CATEGORY_KEYWORD) || next_line_in_file.to_s.include?(FEATURE_CATEGORY_KEYWORD)
+ next
+ end
+
+ line_number = file_lines.find_index(changed_line.delete_prefix('+'))
+ next unless line_number
+
+ suggested_line = file_lines[line_number]
+
+ text = format(comment(FEATURE_CATEGORY_SUGGESTION), suggested_line: suggested_line)
+ markdown(text, file: filename, line: line_number + 1)
+ end
end
private
diff --git a/tooling/danger/user_types.rb b/tooling/danger/user_types.rb
deleted file mode 100644
index 8320c43ae93..00000000000
--- a/tooling/danger/user_types.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-# frozen_string_literal: true
-
-module Tooling
- module Danger
- module UserTypes
- FILE_PATH = "app/models/concerns/has_user_type.rb"
- BOT_USER_TYPES_CHANGE_INDICATOR_REGEX = %r{BOT_USER_TYPES}.freeze
- BOT_USER_TYPES_CHANGED_WARNING = <<~MSG
- You are changing BOT_USER_TYPES in `app/models/concerns/has_user_type.rb`.
- If you are adding or removing new bots, remember to update the `active_billable_users` index with the new value.
- If the bot is not billable, remember to make sure that it's not counted as a billable user.
- MSG
-
- def bot_user_types_change_warning
- return unless impacted?
-
- warn BOT_USER_TYPES_CHANGED_WARNING if bot_user_types_impacted?
- end
-
- private
-
- def impacted?
- helper.modified_files.include?(FILE_PATH)
- end
-
- def bot_user_types_impacted?
- helper.changed_lines(FILE_PATH).any? { |change| change =~ BOT_USER_TYPES_CHANGE_INDICATOR_REGEX }
- end
- end
- end
-end
diff --git a/tooling/lib/tooling/view_to_js_mappings.rb b/tooling/lib/tooling/view_to_js_mappings.rb
new file mode 100644
index 00000000000..76704a04469
--- /dev/null
+++ b/tooling/lib/tooling/view_to_js_mappings.rb
@@ -0,0 +1,77 @@
+# frozen_string_literal: true
+
+require_relative '../../../lib/gitlab_edition'
+
+# Returns JS files that are related to the Rails views files that were changed in the MR.
+module Tooling
+ class ViewToJsMappings
+ # The HTML attribute value pattern we're looking for to match an HTML file to a JS file.
+ HTML_ATTRIBUTE_VALUE_REGEXP = /js-[-\w]+/.freeze
+
+ # Search for Rails partials included in an HTML file
+ RAILS_PARTIAL_INVOCATION_REGEXP = %r{(?:render|render_if_exist)(?: |\()(?:partial: ?)?['"]([\w/-]+)['"]}.freeze
+
+ def initialize(view_base_folder: 'app/views', js_base_folder: 'app/assets/javascripts')
+ @view_base_folders = folders_for_available_editions(view_base_folder)
+ @js_base_folders = folders_for_available_editions(js_base_folder)
+ end
+
+ def execute(changed_files)
+ changed_view_files = view_files(changed_files)
+
+ partials = changed_view_files.flat_map do |file|
+ find_partials(file)
+ end
+
+ files_to_scan = changed_view_files + partials
+ js_tags = files_to_scan.flat_map do |file|
+ find_pattern_in_file(file, HTML_ATTRIBUTE_VALUE_REGEXP)
+ end
+ js_tags_regexp = Regexp.union(js_tags)
+
+ @js_base_folders.flat_map do |js_base_folder|
+ Dir["#{js_base_folder}/**/*.{js,vue}"].select do |js_file|
+ file_content = File.read(js_file)
+ js_tags_regexp.match?(file_content)
+ end
+ end
+ end
+
+ # Keep the files that are in the @view_base_folders folder
+ def view_files(changed_files)
+ changed_files.select do |filename|
+ filename.start_with?(*@view_base_folders) &&
+ File.exist?(filename)
+ end
+ end
+
+ def folders_for_available_editions(base_folder)
+ foss_prefix = base_folder
+ extension_prefixes = ::GitlabEdition.extensions.map { |prefix| "#{prefix}/#{foss_prefix}" }
+ [foss_prefix, *extension_prefixes]
+ end
+
+ # Note: We only search for partials with depth 1. We don't do recursive search, as
+ # it is probably not necessary for a first iteration.
+ def find_partials(file)
+ partial_paths = find_pattern_in_file(file, RAILS_PARTIAL_INVOCATION_REGEXP)
+ partial_paths.flat_map do |partial_path|
+ view_file_folder = File.dirname(file)
+ partial_relative_folder = File.dirname(partial_path)
+
+ dirname =
+ if partial_relative_folder == '.' # The partial is in the same folder as the HTML file
+ view_file_folder
+ else
+ File.join(view_file_folder, partial_relative_folder)
+ end
+
+ Dir["#{dirname}/_#{File.basename(partial_path)}.*"]
+ end
+ end
+
+ def find_pattern_in_file(file, pattern)
+ File.read(file).scan(pattern).flatten.uniq
+ end
+ end
+end
diff --git a/tooling/quality/test_level.rb b/tooling/quality/test_level.rb
index 29da7dddd03..31196290de4 100644
--- a/tooling/quality/test_level.rb
+++ b/tooling/quality/test_level.rb
@@ -83,9 +83,12 @@ module Quality
def level_for(file_path)
case file_path
- # Detect migration first since some background migration tests are under
- # spec/lib/gitlab/background_migration and tests under spec/lib are unit by default
- when regexp(:migration), regexp(:background_migration)
+ # Detect background migration first since some are under
+ # spec/lib/gitlab/background_migration
+ # and tests under spec/lib are unit by default
+ when regexp(:background_migration)
+ :background_migration
+ when regexp(:migration)
:migration
# Detect frontend fixture before matching other unit tests
when regexp(:frontend_fixture)
@@ -101,10 +104,6 @@ module Quality
end
end
- def background_migration?(file_path)
- !!(file_path =~ regexp(:background_migration))
- end
-
private
def prefixes_for_pattern
@@ -130,14 +129,8 @@ module Quality
end
end
- def migration_and_background_migration_folders
- TEST_LEVEL_FOLDERS.fetch(:migration) + TEST_LEVEL_FOLDERS.fetch(:background_migration)
- end
-
def folders_pattern(level)
case level
- when :migration
- "{#{migration_and_background_migration_folders.join(',')}}"
when :all
'**'
else
@@ -147,8 +140,6 @@ module Quality
def folders_regex(level)
case level
- when :migration
- "(#{migration_and_background_migration_folders.join('|')})/"
when :all
''
else