summaryrefslogtreecommitdiff
path: root/tooling
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 07:33:21 +0000
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /tooling
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
downloadgitlab-ce-36a59d088eca61b834191dacea009677a96c052f.tar.gz
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'tooling')
-rwxr-xr-xtooling/bin/find_change_diffs6
-rwxr-xr-xtooling/bin/find_codeowners6
-rw-r--r--tooling/config/CODEOWNERS.yml58
-rw-r--r--tooling/danger/project_helper.rb3
-rw-r--r--tooling/danger/specs.rb2
-rw-r--r--tooling/lib/tooling/find_codeowners.rb103
-rw-r--r--tooling/quality/test_level.rb6
7 files changed, 177 insertions, 7 deletions
diff --git a/tooling/bin/find_change_diffs b/tooling/bin/find_change_diffs
index 7857945ea74..b28b20df0f4 100755
--- a/tooling/bin/find_change_diffs
+++ b/tooling/bin/find_change_diffs
@@ -33,6 +33,8 @@ end
Gitlab.merge_request_changes(mr_project_path, mr_iid).changes.each do |change|
next if change['diff'].empty?
- output_diffs_dir.join(File.dirname(change['new_path'])).mkpath
- output_diffs_dir.join("#{change['new_path']}.diff").write(change['diff'])
+ ext = change['deleted_file'] ? ".deleted.diff" : ".diff"
+ new_path = output_diffs_dir.join("#{change['new_path']}#{ext}")
+ new_path.dirname.mkpath
+ new_path.write(change['diff'])
end
diff --git a/tooling/bin/find_codeowners b/tooling/bin/find_codeowners
new file mode 100755
index 00000000000..2c028b3162e
--- /dev/null
+++ b/tooling/bin/find_codeowners
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+# frozen_string_literal: true
+
+require_relative '../lib/tooling/find_codeowners'
+
+Tooling::FindCodeowners.new.execute
diff --git a/tooling/config/CODEOWNERS.yml b/tooling/config/CODEOWNERS.yml
new file mode 100644
index 00000000000..d867c8c22fc
--- /dev/null
+++ b/tooling/config/CODEOWNERS.yml
@@ -0,0 +1,58 @@
+# This is supposed to be used with:
+# tooling/bin/find_codeowners tooling/config/CODEOWNERS.yml
+# And paste the contents into .gitlab/CODEOWNERS
+
+'[Authentication and Authorization]':
+ '@gitlab-org/manage/authentication-and-authorization':
+ allow:
+ keywords:
+ - password
+ - auth
+ - token
+ patterns:
+ - '/{,ee/}app/**/*%{keyword}*{/**/*,}'
+ - '/{,ee/}config/**/*%{keyword}*{/**/*,}'
+ - '/{,ee/}lib/**/*%{keyword}*{/**/*,}'
+ deny:
+ keywords:
+ - author.
+ - author_
+ - authored
+ - authoring
+ - .png
+ - .svg
+ - deploy_token
+ - runner{,s}_token
+ - job_token
+ - autocomplete_tokens
+ - dast_site_token
+ - reset_prometheus_token
+ - reset_registration_token
+ - runners_registration_token
+ - terraform_registry_token
+ - tokenizer
+ - filtered_search
+ - /alert_management/
+ - /analytics/
+ - /bitbucket/
+ - /clusters/
+ - /clusters_list/
+ - /dast/
+ - /dast_profiles/
+ - /dast_site_tokens/
+ - /dast_site_validation/
+ - /dependency_proxy/
+ - /error_tracking/
+ - /google_api/
+ - /google_cloud/
+ - /jira_connect/
+ - /kubernetes/
+ - /protected_environments/
+ - /config/feature_flags/development/jira_connect_
+ - /config/metrics/
+ - /app/controllers/groups/dependency_proxy_auth_controller.rb
+ - /app/finders/ci/auth_job_finder.rb
+ - /ee/config/metrics/
+ - /lib/gitlab/conan_token.rb
+ patterns:
+ - '**/*%{keyword}*{/**/*,}'
diff --git a/tooling/danger/project_helper.rb b/tooling/danger/project_helper.rb
index fc87498f5d0..c0afd9b7319 100644
--- a/tooling/danger/project_helper.rb
+++ b/tooling/danger/project_helper.rb
@@ -26,6 +26,7 @@ module Tooling
%r{\Adoc/.*(\.(md|png|gif|jpg|yml))\z} => :docs,
%r{\A(CONTRIBUTING|LICENSE|MAINTENANCE|PHILOSOPHY|PROCESS|README)(\.md)?\z} => :docs,
%r{\Adata/whats_new/} => :docs,
+ %r{\Adb/docs/.yml\z} => :docs,
%r{\Adata/deprecations/} => :none,
%r{\Adata/removals/} => :none,
@@ -100,6 +101,8 @@ module Tooling
%r{\A\.editorconfig\z} => :tooling,
%r{Dangerfile\z} => :tooling,
%r{\A((ee|jh)/)?(danger/|tooling/danger/)} => :tooling,
+ %r{\A((ee|jh)/)?(lib/)?scripts/.*\.rb} => [:backend, :tooling],
+ %r{\A((ee|jh)/)?(lib/)?scripts/.*\.js} => [:frontend, :tooling],
%r{\A((ee|jh)/)?scripts/} => :tooling,
%r{\Atooling/} => :tooling,
%r{(CODEOWNERS)} => :tooling,
diff --git a/tooling/danger/specs.rb b/tooling/danger/specs.rb
index 466230bb86b..36ec83dd7d2 100644
--- a/tooling/danger/specs.rb
+++ b/tooling/danger/specs.rb
@@ -5,7 +5,7 @@ module Tooling
module Specs
SPEC_FILES_REGEX = 'spec/'
EE_PREFIX = 'ee/'
- MATCH_WITH_ARRAY_REGEX = /(?<to>to\(?\s*)(?<matcher>match|eq)(?<expectation>[( ]?\[)/.freeze
+ MATCH_WITH_ARRAY_REGEX = /(?<to>to\(?\s*)(?<matcher>match|eq)(?<expectation>[( ]?\[[^\]]+)/.freeze
SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT
```suggestion
%<suggested_line>s
diff --git a/tooling/lib/tooling/find_codeowners.rb b/tooling/lib/tooling/find_codeowners.rb
new file mode 100644
index 00000000000..35d8a9d7461
--- /dev/null
+++ b/tooling/lib/tooling/find_codeowners.rb
@@ -0,0 +1,103 @@
+# frozen_string_literal: true
+
+require 'yaml'
+
+module Tooling
+ class FindCodeowners
+ def execute
+ load_definitions.each do |section, group_defintions|
+ puts section
+
+ group_defintions.each do |group, list|
+ matched_files = git_ls_files.each_line.select do |line|
+ list[:allow].find do |pattern|
+ path = "/#{line.chomp}"
+
+ path_matches?(pattern, path) &&
+ list[:deny].none? { |pattern| path_matches?(pattern, path) }
+ end
+ end
+
+ consolidated = consolidate_paths(matched_files)
+ consolidated_again = consolidate_paths(consolidated)
+
+ # Consider the directory structure is a tree structure:
+ # https://en.wikipedia.org/wiki/Tree_(data_structure)
+ # After we consolidated the leaf entries, it could be possible that
+ # we can consolidate further for the new leaves. Repeat this
+ # process until we see no improvements.
+ while consolidated_again.size < consolidated.size
+ consolidated = consolidated_again
+ consolidated_again = consolidate_paths(consolidated)
+ end
+
+ consolidated.each do |file|
+ puts "/#{file.chomp} #{group}"
+ end
+ end
+ end
+ end
+
+ def load_definitions
+ result = load_config
+
+ result.each do |section, group_defintions|
+ group_defintions.each do |group, definitions|
+ definitions.transform_values! do |rules|
+ rules[:keywords].flat_map do |keyword|
+ rules[:patterns].map do |pattern|
+ pattern % { keyword: keyword }
+ end
+ end
+ end
+ end
+ end
+
+ result
+ end
+
+ def load_config
+ config_path = "#{__dir__}/../../config/CODEOWNERS.yml"
+
+ if YAML.respond_to?(:safe_load_file) # Ruby 3.0+
+ YAML.safe_load_file(config_path, symbolize_names: true)
+ else
+ YAML.safe_load(File.read(config_path), symbolize_names: true)
+ end
+ end
+
+ # Copied and modified from ee/lib/gitlab/code_owners/file.rb
+ def path_matches?(pattern, path)
+ # `FNM_DOTMATCH` makes sure we also match files starting with a `.`
+ # `FNM_PATHNAME` makes sure ** matches path separators
+ flags = ::File::FNM_DOTMATCH | ::File::FNM_PATHNAME
+
+ # BEGIN extension
+ flags |= ::File::FNM_EXTGLOB
+ # END extension
+
+ ::File.fnmatch?(pattern, path, flags)
+ end
+
+ def consolidate_paths(matched_files)
+ matched_files.group_by(&File.method(:dirname)).flat_map do |dir, files|
+ # First line is the dir itself
+ if find_dir_maxdepth_1(dir).lines.drop(1).sort == files.sort
+ "#{dir}\n"
+ else
+ files
+ end
+ end.sort
+ end
+
+ private
+
+ def find_dir_maxdepth_1(dir)
+ `find #{dir} -maxdepth 1`
+ end
+
+ def git_ls_files
+ @git_ls_files ||= `git ls-files`
+ end
+ end
+end
diff --git a/tooling/quality/test_level.rb b/tooling/quality/test_level.rb
index fd86708bb7d..6e58241bccb 100644
--- a/tooling/quality/test_level.rb
+++ b/tooling/quality/test_level.rb
@@ -139,8 +139,7 @@ module Quality
case level
when :migration
"{#{migration_and_background_migration_folders.join(',')}}"
- # Geo specs aren't in a specific folder, but they all have the :geo tag, so we must search for them globally
- when :all, :geo
+ when :all
'**'
else
"{#{TEST_LEVEL_FOLDERS.fetch(level).join(',')}}"
@@ -151,8 +150,7 @@ module Quality
case level
when :migration
"(#{migration_and_background_migration_folders.join('|')})"
- # Geo specs aren't in a specific folder, but they all have the :geo tag, so we must search for them globally
- when :all, :geo
+ when :all
''
else
"(#{TEST_LEVEL_FOLDERS.fetch(level).join('|')})"