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-03-29 12:10:35 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-03-29 12:10:35 +0300
commit55dea17c8d10d1b25cd25f1cdaeaed64332995a7 (patch)
treed8deec499e9aacae38b95cb509f9dc7873b0652a /tooling
parentf0224e32ca39fe7b261a8d6bcec64bb449c65856 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'tooling')
-rwxr-xr-xtooling/bin/js_to_system_specs_mappings11
-rwxr-xr-xtooling/bin/view_to_js_mappings7
-rwxr-xr-xtooling/bin/view_to_system_specs_mappings9
-rw-r--r--tooling/lib/tooling/mappings/base.rb12
-rw-r--r--tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb18
-rw-r--r--tooling/lib/tooling/mappings/view_to_js_mappings.rb30
-rw-r--r--tooling/lib/tooling/mappings/view_to_system_specs_mappings.rb64
7 files changed, 112 insertions, 39 deletions
diff --git a/tooling/bin/js_to_system_specs_mappings b/tooling/bin/js_to_system_specs_mappings
index 3e9d9cb4c5f..22d1dbb6590 100755
--- a/tooling/bin/js_to_system_specs_mappings
+++ b/tooling/bin/js_to_system_specs_mappings
@@ -3,12 +3,7 @@
require_relative '../lib/tooling/mappings/js_to_system_specs_mappings'
-changes = ARGV.shift
-matching_tests = ARGV.shift
+changes_file = ARGV.shift
+matching_tests_paths = ARGV.shift
-changed_files = File.read(changes).split(' ')
-matching_test_files = File.read(matching_tests).split(' ')
-
-system_tests = Tooling::Mappings::JsToSystemSpecsMappings.new.execute(changed_files)
-
-File.write(matching_tests, (matching_test_files + system_tests).join(' '))
+Tooling::Mappings::JsToSystemSpecsMappings.new(changes_file, matching_tests_paths).execute
diff --git a/tooling/bin/view_to_js_mappings b/tooling/bin/view_to_js_mappings
index 483003aac5e..51d7cc11ed8 100755
--- a/tooling/bin/view_to_js_mappings
+++ b/tooling/bin/view_to_js_mappings
@@ -3,8 +3,7 @@
require_relative '../lib/tooling/mappings/view_to_js_mappings'
-changes = ARGV.shift
-output_file = ARGV.shift
-changed_files = File.read(changes).split(' ')
+changes_file = ARGV.shift
+matching_tests_paths = ARGV.shift
-File.write(output_file, Tooling::Mappings::ViewToJsMappings.new.execute(changed_files).join(' '))
+Tooling::Mappings::ViewToJsMappings.new(changes_file, matching_tests_paths).execute
diff --git a/tooling/bin/view_to_system_specs_mappings b/tooling/bin/view_to_system_specs_mappings
new file mode 100755
index 00000000000..b2e3f2a132a
--- /dev/null
+++ b/tooling/bin/view_to_system_specs_mappings
@@ -0,0 +1,9 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require_relative '../lib/tooling/mappings/view_to_system_specs_mappings'
+
+changes_file = ARGV.shift
+output_file = ARGV.shift
+
+Tooling::Mappings::ViewToSystemSpecsMappings.new(changes_file, output_file).execute
diff --git a/tooling/lib/tooling/mappings/base.rb b/tooling/lib/tooling/mappings/base.rb
index 3db4d1dbb9d..27a9a0925b0 100644
--- a/tooling/lib/tooling/mappings/base.rb
+++ b/tooling/lib/tooling/mappings/base.rb
@@ -9,18 +9,6 @@ module Tooling
class Base
include Helpers::FileHandler
- # Input: A list of space-separated files
- # Output: A list of space-separated specs files (JS, Ruby, ...)
- def execute(changed_files)
- raise "Not Implemented"
- end
-
- # Input: A list of space-separated files
- # Output: array/hash of files
- def filter_files(changed_files)
- raise "Not Implemented"
- end
-
# Input: A folder
# Output: An array of folders, each prefixed with a GitLab edition
def folders_for_available_editions(base_folder)
diff --git a/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb b/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
index e78ce266a32..f0fb5293a68 100644
--- a/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
+++ b/tooling/lib/tooling/mappings/js_to_system_specs_mappings.rb
@@ -9,7 +9,11 @@ require_relative '../../../../lib/gitlab_edition'
module Tooling
module Mappings
class JsToSystemSpecsMappings < Base
- def initialize(js_base_folder: 'app/assets/javascripts', system_specs_base_folder: 'spec/features')
+ def initialize(
+ changes_file, matching_tests_paths,
+ js_base_folder: 'app/assets/javascripts', system_specs_base_folder: 'spec/features')
+ @changed_files = read_array_from_file(changes_file)
+ @matching_tests_paths = matching_tests_paths
@js_base_folder = js_base_folder
@js_base_folders = folders_for_available_editions(js_base_folder)
@system_specs_base_folder = system_specs_base_folder
@@ -23,20 +27,22 @@ module Tooling
}x
end
- def execute(changed_files)
- filter_files(changed_files).flat_map do |edition, js_files|
+ def execute
+ matching_system_tests = filter_files.flat_map do |edition, js_files|
js_keywords_regexp = Regexp.union(construct_js_keywords(js_files))
system_specs_for_edition(edition).select do |system_spec_file|
system_spec_file if js_keywords_regexp.match?(system_spec_file)
end
end
+
+ write_array_to_file(matching_tests_paths, matching_system_tests)
end
# Keep the files that are in the @js_base_folders folders
#
# Returns a hash, where the key is the GitLab edition, and the values the JS specs
- def filter_files(changed_files)
+ def filter_files
selected_files = changed_files.select do |filename|
filename.start_with?(*@js_base_folders) && File.exist?(filename)
end
@@ -57,6 +63,10 @@ module Tooling
all_files_in_folders_glob = File.join(edition, all_files_in_folders_glob) if edition
Dir[all_files_in_folders_glob].select { |f| File.file?(f) }
end
+
+ private
+
+ attr_reader :changed_files, :matching_tests_paths
end
end
end
diff --git a/tooling/lib/tooling/mappings/view_to_js_mappings.rb b/tooling/lib/tooling/mappings/view_to_js_mappings.rb
index bf305d6738d..fd2db6b6d7e 100644
--- a/tooling/lib/tooling/mappings/view_to_js_mappings.rb
+++ b/tooling/lib/tooling/mappings/view_to_js_mappings.rb
@@ -13,35 +13,39 @@ module Tooling
# Search for Rails partials included in an HTML file
RAILS_PARTIAL_INVOCATION_REGEXP = %r{(?:render|render_if_exists)(?: |\()(?: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)
+ def initialize(
+ changes_file, matching_tests_paths,
+ view_base_folder: 'app/views', js_base_folder: 'app/assets/javascripts')
+ @changed_files = read_array_from_file(changes_file)
+ @matching_tests_paths = matching_tests_paths
+ @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 = filter_files(changed_files)
-
- partials = changed_view_files.flat_map do |file|
+ def execute
+ partials = filter_files.flat_map do |file|
find_partials(file)
end
- files_to_scan = changed_view_files + partials
+ files_to_scan = filter_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|
+ matching_js_files = @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
+
+ write_array_to_file(matching_tests_paths, matching_js_files)
end
# Keep the files that are in the @view_base_folders folder
- def filter_files(changed_files)
- changed_files.select do |filename|
+ def filter_files
+ @_filter_files ||= changed_files.select do |filename|
filename.start_with?(*@view_base_folders) &&
File.exist?(filename)
end
@@ -69,6 +73,10 @@ module Tooling
def find_pattern_in_file(file, pattern)
File.read(file).scan(pattern).flatten.uniq
end
+
+ private
+
+ attr_reader :changed_files, :matching_tests_paths
end
end
end
diff --git a/tooling/lib/tooling/mappings/view_to_system_specs_mappings.rb b/tooling/lib/tooling/mappings/view_to_system_specs_mappings.rb
new file mode 100644
index 00000000000..227f2c6e62b
--- /dev/null
+++ b/tooling/lib/tooling/mappings/view_to_system_specs_mappings.rb
@@ -0,0 +1,64 @@
+# frozen_string_literal: true
+
+require_relative 'base'
+require_relative '../../../../lib/gitlab_edition'
+
+# Returns system specs files that are related to the Rails views files that were changed in the MR.
+module Tooling
+ module Mappings
+ class ViewToSystemSpecsMappings < Base
+ def initialize(changes_file, output_file, view_base_folder: 'app/views')
+ @output_file = output_file
+ @changed_files = read_array_from_file(changes_file)
+ @view_base_folders = folders_for_available_editions(view_base_folder)
+ end
+
+ def execute
+ found_system_specs = []
+
+ filter_files.each do |modified_view_file|
+ system_specs_exact_match = find_system_specs_exact_match(modified_view_file)
+ if system_specs_exact_match
+ found_system_specs << system_specs_exact_match
+ next
+ else
+ system_specs_parent_folder_match = find_system_specs_parent_folder_match(modified_view_file)
+ found_system_specs += system_specs_parent_folder_match unless system_specs_parent_folder_match.empty?
+ end
+ end
+
+ write_array_to_file(output_file, found_system_specs.compact.uniq.sort)
+ end
+
+ private
+
+ attr_reader :changed_files, :output_file, :view_base_folders
+
+ # Keep the views files that are in the @view_base_folders folder
+ def filter_files
+ @_filter_files ||= changed_files.select do |filename|
+ filename.start_with?(*view_base_folders) &&
+ File.basename(filename).end_with?('.html.haml') &&
+ File.exist?(filename)
+ end
+ end
+
+ def find_system_specs_exact_match(view_file)
+ potential_spec_file = to_feature_spec_folder(view_file).sub('.html.haml', '_spec.rb')
+
+ potential_spec_file if File.exist?(potential_spec_file)
+ end
+
+ def find_system_specs_parent_folder_match(view_file)
+ parent_system_specs_folder = File.dirname(to_feature_spec_folder(view_file))
+
+ Dir["#{parent_system_specs_folder}/**/*_spec.rb"]
+ end
+
+ # e.g. go from app/views/groups/merge_requests.html.haml to spec/features/groups/merge_requests.html.haml
+ def to_feature_spec_folder(view_file)
+ view_file.sub(%r{(ee/|jh/)?app/views}, '\1spec/features')
+ end
+ end
+ end
+end