diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 08:43:02 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 08:43:02 +0000 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /tooling | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) | |
download | gitlab-ce-d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb.tar.gz |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'tooling')
-rw-r--r-- | tooling/danger/product_intelligence.rb | 3 | ||||
-rw-r--r-- | tooling/danger/project_helper.rb | 9 | ||||
-rw-r--r-- | tooling/danger/specs.rb | 59 | ||||
-rw-r--r-- | tooling/deprecations/docs.rb | 2 | ||||
-rw-r--r-- | tooling/graphql/docs/templates/default.md.haml | 6 | ||||
-rw-r--r-- | tooling/lib/tooling/helm3_client.rb | 2 | ||||
-rw-r--r-- | tooling/quality/test_level.rb | 24 |
7 files changed, 95 insertions, 10 deletions
diff --git a/tooling/danger/product_intelligence.rb b/tooling/danger/product_intelligence.rb index 30c961184f5..848f99eeff5 100644 --- a/tooling/danger/product_intelligence.rb +++ b/tooling/danger/product_intelligence.rb @@ -30,7 +30,7 @@ module Tooling ].freeze def missing_labels - return [] unless helper.ci? + return [] if !helper.ci? || helper.mr_has_labels?('growth experiment') labels = [] labels << 'product intelligence' unless helper.mr_has_labels?('product intelligence') @@ -66,7 +66,6 @@ module Tooling js_patterns = Regexp.union( 'Tracking.event', /\btrack\(/, - 'data-track-event', 'data-track-action' ) all_changed_files.select do |file| diff --git a/tooling/danger/project_helper.rb b/tooling/danger/project_helper.rb index 109f77ed4d1..c552a75bba8 100644 --- a/tooling/danger/project_helper.rb +++ b/tooling/danger/project_helper.rb @@ -113,6 +113,7 @@ module Tooling generator_templates/usage_metric_definition/metric_definition\.yml)\z}x => [:backend, :product_intelligence], %r{\A((ee|jh)/)?app/(?!assets|views)[^/]+} => :backend, %r{\A((ee|jh)/)?(bin|config|generator_templates|lib|rubocop)/} => :backend, + %r{\A((ee|jh)/)?spec/migrations} => :database, %r{\A((ee|jh)/)?spec/} => :backend, %r{\A((ee|jh)/)?vendor/} => :backend, %r{\A(Gemfile|Gemfile.lock|Rakefile)\z} => :backend, @@ -174,8 +175,16 @@ module Tooling ee? ? 'gitlab' : 'gitlab-foss' end + def file_lines(filename) + read_file(filename).lines(chomp: true) + end + private + def read_file(filename) + File.read(filename) + end + def ee? # Support former project name for `dev` and support local Danger run %w[gitlab gitlab-ee].include?(ENV['CI_PROJECT_NAME']) || Dir.exist?(File.expand_path('../../../ee', __dir__)) diff --git a/tooling/danger/specs.rb b/tooling/danger/specs.rb new file mode 100644 index 00000000000..466230bb86b --- /dev/null +++ b/tooling/danger/specs.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true + +module Tooling + module Danger + module Specs + SPEC_FILES_REGEX = 'spec/' + EE_PREFIX = 'ee/' + MATCH_WITH_ARRAY_REGEX = /(?<to>to\(?\s*)(?<matcher>match|eq)(?<expectation>[( ]?\[)/.freeze + SUGGEST_MR_COMMENT = <<~SUGGEST_COMMENT + ```suggestion + %<suggested_line>s + ``` + + If order of the result is not important, please consider using `match_array` to avoid flakiness. + SUGGEST_COMMENT + + def changed_specs_files(ee: :include) + changed_files = helper.all_changed_files + folder_prefix = + case ee + when :include + "(#{EE_PREFIX})?" + when :only + EE_PREFIX + when :exclude + nil + end + + changed_files.grep(%r{\A#{folder_prefix}#{SPEC_FILES_REGEX}}) + end + + def add_suggestions_for_match_with_array(filename) + added_lines = added_line_matching_match_with_array(filename) + return if added_lines.empty? + + spec_file_lines = project_helper.file_lines(filename) + + added_lines.each_with_object([]) do |added_line, processed_line_numbers| + line_number = find_line_number(spec_file_lines, added_line.delete_prefix('+'), exclude_indexes: processed_line_numbers) + processed_line_numbers << line_number + markdown(format(SUGGEST_MR_COMMENT, suggested_line: spec_file_lines[line_number].gsub(MATCH_WITH_ARRAY_REGEX, '\k<to>match_array\k<expectation>')), file: filename, line: line_number.succ) + end + end + + def added_line_matching_match_with_array(filename) + helper.changed_lines(filename).grep(/\A\+ /).grep(MATCH_WITH_ARRAY_REGEX) + end + + private + + def find_line_number(file_lines, searched_line, exclude_indexes: []) + file_lines.each_with_index do |file_line, index| + next if exclude_indexes.include?(index) + break index if file_line == searched_line + end + end + end + end +end diff --git a/tooling/deprecations/docs.rb b/tooling/deprecations/docs.rb index adc3e0edb10..67ff7a932b4 100644 --- a/tooling/deprecations/docs.rb +++ b/tooling/deprecations/docs.rb @@ -20,7 +20,7 @@ module Deprecations YAML.load_file(file) end - deprecations = VersionSorter.rsort(deprecations) { |d| d["removal_milestone"] } + deprecations = VersionSorter.sort(deprecations) { |d| d["removal_milestone"] } milestones = deprecations.map { |d| d["removal_milestone"] }.uniq diff --git a/tooling/graphql/docs/templates/default.md.haml b/tooling/graphql/docs/templates/default.md.haml index 7d42fb3a9f8..fad954ebb01 100644 --- a/tooling/graphql/docs/templates/default.md.haml +++ b/tooling/graphql/docs/templates/default.md.haml @@ -18,8 +18,12 @@ in [Removed Items](../removed_items.md). <!-- vale off --> - <!-- Docs linting disabled after this line. --> + <!-- Vale linting disabled after this line. --> <!-- See https://docs.gitlab.com/ee/development/documentation/testing.html#disable-vale-tests --> + + <!-- markdownlint-disable MD044 --> + <!-- MD044/proper-names test disabled after this line to make page compatible with markdownlint-cli 0.29.0. --> + <!-- See https://docs.gitlab.com/ee/development/documentation/testing.html#disable-markdownlint-tests --> \ :plain diff --git a/tooling/lib/tooling/helm3_client.rb b/tooling/lib/tooling/helm3_client.rb index 3743138f27e..6e4a35e82f1 100644 --- a/tooling/lib/tooling/helm3_client.rb +++ b/tooling/lib/tooling/helm3_client.rb @@ -19,7 +19,7 @@ module Tooling end def last_update - @last_update ||= Time.parse(self[:last_update]) + @last_update ||= self[:last_update] ? Time.parse(self[:last_update]) : nil end end diff --git a/tooling/quality/test_level.rb b/tooling/quality/test_level.rb index ad9de067375..83cbe7a1f19 100644 --- a/tooling/quality/test_level.rb +++ b/tooling/quality/test_level.rb @@ -60,20 +60,20 @@ module Quality system: ['features'] }.freeze - attr_reader :prefix + attr_reader :prefixes - def initialize(prefix = nil) - @prefix = prefix + def initialize(prefixes = nil) + @prefixes = Array(prefixes) @patterns = {} @regexps = {} end def pattern(level) - @patterns[level] ||= "#{prefix}spec/#{folders_pattern(level)}{,/**/}*#{suffix(level)}" + @patterns[level] ||= "#{prefixes_for_pattern}spec/#{folders_pattern(level)}{,/**/}*#{suffix(level)}" end def regexp(level) - @regexps[level] ||= Regexp.new("#{prefix}spec/#{folders_regex(level)}").freeze + @regexps[level] ||= Regexp.new("#{prefixes_for_regex}spec/#{folders_regex(level)}").freeze end def level_for(file_path) @@ -102,6 +102,20 @@ module Quality private + def prefixes_for_pattern + return '' if prefixes.empty? + + "{#{prefixes.join(',')}}" + end + + def prefixes_for_regex + return '' if prefixes.empty? + + regex_prefix = prefixes.map(&Regexp.method(:escape)).join('|') + + "(#{regex_prefix})" + end + def suffix(level) case level when :frontend_fixture |