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>2020-06-18 14:18:50 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-06-18 14:18:50 +0300
commit8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch)
treea77e7fe7a93de11213032ed4ab1f33a3db51b738 /tooling
parent00b35af3db1abfe813a778f643dad221aad51fca (diff)
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'tooling')
-rwxr-xr-xtooling/bin/find_foss_tests29
-rw-r--r--tooling/lib/tooling/test_file_finder.rb78
-rw-r--r--tooling/overcommit/Gemfile2
-rw-r--r--tooling/overcommit/Gemfile.lock61
4 files changed, 147 insertions, 23 deletions
diff --git a/tooling/bin/find_foss_tests b/tooling/bin/find_foss_tests
new file mode 100755
index 00000000000..c694210ad40
--- /dev/null
+++ b/tooling/bin/find_foss_tests
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require_relative '../../lib/gitlab/popen'
+require_relative '../lib/tooling/test_file_finder'
+
+require 'gitlab'
+
+gitlab_token = ENV.fetch('DANGER_GITLAB_API_TOKEN', '')
+
+Gitlab.configure do |config|
+ config.endpoint = 'https://gitlab.com/api/v4'
+ config.private_token = gitlab_token
+end
+
+output_file = ARGV.shift
+
+mr_project_path = ENV.fetch('CI_MERGE_REQUEST_PROJECT_PATH')
+mr_iid = ENV.fetch('CI_MERGE_REQUEST_IID')
+
+mr_changes = Gitlab.merge_request_changes(mr_project_path, mr_iid)
+changed_files = mr_changes.changes.map { |change| change['new_path'] }
+
+tests_to_run = changed_files.flat_map do |file|
+ test_files = Tooling::TestFileFinder.new(file, foss_test_only: true).test_files
+ test_files.select { |f| File.exist?(f) }
+end
+
+File.write(output_file, tests_to_run.uniq.join(' '))
diff --git a/tooling/lib/tooling/test_file_finder.rb b/tooling/lib/tooling/test_file_finder.rb
new file mode 100644
index 00000000000..4cf7ad35922
--- /dev/null
+++ b/tooling/lib/tooling/test_file_finder.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+require 'set'
+
+module Tooling
+ class TestFileFinder
+ EE_PREFIX = 'ee/'
+
+ def initialize(file, foss_test_only: false)
+ @file = file
+ @foss_test_only = foss_test_only
+ end
+
+ def test_files
+ impacted_tests = ee_impact | non_ee_impact
+ impacted_tests.impact(@file)
+ end
+
+ private
+
+ attr_reader :file, :foss_test_only, :result
+
+ class ImpactedTestFile
+ attr_reader :pattern_matchers
+
+ def initialize
+ @pattern_matchers = {}
+
+ yield self if block_given?
+ end
+
+ def associate(pattern, &block)
+ @pattern_matchers[pattern] = block
+ end
+
+ def impact(file)
+ @pattern_matchers.each_with_object(Set.new) do |(pattern, block), result|
+ if (match = pattern.match(file))
+ result << block.call(match)
+ end
+ end.to_a
+ end
+
+ def |(other)
+ self.class.new do |combined_matcher|
+ self.pattern_matchers.each do |pattern, block|
+ combined_matcher.associate(pattern, &block)
+ end
+ other.pattern_matchers.each do |pattern, block|
+ combined_matcher.associate(pattern, &block)
+ end
+ end
+ end
+ end
+
+ def ee_impact
+ ImpactedTestFile.new do |impact|
+ unless foss_test_only
+ impact.associate(%r{^#{EE_PREFIX}app/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}app/(.*/)ee/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/#{match[1]}#{match[2]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}lib/(.+)\.rb$}) { |match| "#{EE_PREFIX}spec/lib/#{match[1]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}spec/(.+)_spec.rb$}) { |match| match[0] }
+ end
+
+ impact.associate(%r{^#{EE_PREFIX}(?!spec)(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}_spec.rb" }
+ impact.associate(%r{^#{EE_PREFIX}spec/(.*/)ee/(.+)\.rb$}) { |match| "spec/#{match[1]}#{match[2]}.rb" }
+ end
+ end
+
+ def non_ee_impact
+ ImpactedTestFile.new do |impact|
+ impact.associate(%r{^app/(.+)\.rb$}) { |match| "spec/#{match[1]}_spec.rb" }
+ impact.associate(%r{^(tooling/)?lib/(.+)\.rb$}) { |match| "spec/#{match[1]}lib/#{match[2]}_spec.rb" }
+ impact.associate(%r{^spec/(.+)_spec.rb$}) { |match| match[0] }
+ end
+ end
+ end
+end
diff --git a/tooling/overcommit/Gemfile b/tooling/overcommit/Gemfile
index 5525662e43e..120cb1ad8d0 100644
--- a/tooling/overcommit/Gemfile
+++ b/tooling/overcommit/Gemfile
@@ -4,6 +4,6 @@
source 'https://rubygems.org'
gem 'overcommit'
-gem 'gitlab-styles', '~> 3.1.0', require: false
+gem 'gitlab-styles', '~> 4.2.0', require: false
gem 'scss_lint', '~> 0.56.0', require: false
gem 'haml_lint', '~> 0.34.0', require: false
diff --git a/tooling/overcommit/Gemfile.lock b/tooling/overcommit/Gemfile.lock
index 15b80426c03..7ab10f741ed 100644
--- a/tooling/overcommit/Gemfile.lock
+++ b/tooling/overcommit/Gemfile.lock
@@ -1,55 +1,68 @@
GEM
remote: https://rubygems.org/
specs:
+ activesupport (6.0.3)
+ concurrent-ruby (~> 1.0, >= 1.0.2)
+ i18n (>= 0.7, < 2)
+ minitest (~> 5.1)
+ tzinfo (~> 1.1)
+ zeitwerk (~> 2.2, >= 2.2.2)
ast (2.4.0)
childprocess (3.0.0)
- ffi (1.12.1)
- gitlab-styles (3.1.0)
- rubocop (~> 0.74.0)
+ concurrent-ruby (1.1.6)
+ ffi (1.12.2)
+ gitlab-styles (4.2.0)
+ rubocop (~> 0.82.0)
rubocop-gitlab-security (~> 0.1.0)
- rubocop-performance (~> 1.4.1)
- rubocop-rails (~> 2.0)
+ rubocop-performance (~> 1.5.2)
+ rubocop-rails (~> 2.5)
rubocop-rspec (~> 1.36)
haml (5.1.2)
temple (>= 0.8.0)
tilt
- haml_lint (0.34.1)
+ haml_lint (0.34.0)
haml (>= 4.0, < 5.2)
rainbow
rubocop (>= 0.50.0)
sysexits (~> 1.1)
- iniparse (1.4.4)
+ i18n (1.8.2)
+ concurrent-ruby (~> 1.0)
+ iniparse (1.5.0)
jaro_winkler (1.5.4)
- overcommit (0.52.1)
+ minitest (5.11.3)
+ overcommit (0.53.0)
childprocess (>= 0.6.3, < 4)
iniparse (~> 1.4)
parallel (1.19.1)
- parser (2.7.0.2)
+ parser (2.7.1.2)
ast (~> 2.4.0)
- rack (2.1.1)
+ rack (2.0.9)
rainbow (3.0.0)
rake (12.3.3)
- rb-fsevent (0.10.3)
- rb-inotify (0.10.1)
- ffi (~> 1.0)
- rubocop (0.74.0)
+ rb-fsevent (0.10.2)
+ rb-inotify (0.9.10)
+ ffi (>= 0.5.0, < 2)
+ rexml (3.2.4)
+ rubocop (0.82.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
- parser (>= 2.6)
+ parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
+ rexml
ruby-progressbar (~> 1.7)
- unicode-display_width (>= 1.4.0, < 1.7)
+ unicode-display_width (>= 1.4.0, < 2.0)
rubocop-gitlab-security (0.1.1)
rubocop (>= 0.51)
- rubocop-performance (1.4.1)
+ rubocop-performance (1.5.2)
rubocop (>= 0.71.0)
- rubocop-rails (2.4.1)
+ rubocop-rails (2.5.2)
+ activesupport
rack (>= 1.1)
rubocop (>= 0.72.0)
- rubocop-rspec (1.37.1)
+ rubocop-rspec (1.37.0)
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
- sass (3.5.7)
+ sass (3.5.5)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
@@ -59,14 +72,18 @@ GEM
sass (~> 3.5.3)
sysexits (1.2.0)
temple (0.8.2)
+ thread_safe (0.3.6)
tilt (2.0.10)
- unicode-display_width (1.6.1)
+ tzinfo (1.2.7)
+ thread_safe (~> 0.1)
+ unicode-display_width (1.7.0)
+ zeitwerk (2.3.0)
PLATFORMS
ruby
DEPENDENCIES
- gitlab-styles (~> 3.1.0)
+ gitlab-styles (~> 4.2.0)
haml_lint (~> 0.34.0)
overcommit
scss_lint (~> 0.56.0)