diff options
Diffstat (limited to 'tooling')
-rwxr-xr-x | tooling/bin/find_changes | 2 | ||||
-rw-r--r-- | tooling/danger/datateam.rb | 58 | ||||
-rw-r--r-- | tooling/danger/project_helper.rb | 1 | ||||
-rw-r--r-- | tooling/deprecations/docs.rb | 39 | ||||
-rw-r--r-- | tooling/docs/deprecation_handling.rb | 42 |
5 files changed, 102 insertions, 40 deletions
diff --git a/tooling/bin/find_changes b/tooling/bin/find_changes index c6b8bafbd85..8ad5011459b 100755 --- a/tooling/bin/find_changes +++ b/tooling/bin/find_changes @@ -48,7 +48,7 @@ class FindChanges # rubocop:disable Gitlab/NamespacedClass mr_changes = Gitlab.merge_request_changes(mr_project_path, mr_iid) - mr_changes.changes.map { |change| change['new_path'] } + mr_changes.changes.map { |change| change['new_path'] unless change['deleted_file'] }.compact end end diff --git a/tooling/danger/datateam.rb b/tooling/danger/datateam.rb new file mode 100644 index 00000000000..b3779aa13bb --- /dev/null +++ b/tooling/danger/datateam.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +module Tooling + module Danger + module Datateam + CHANGED_SCHEMA_MESSAGE = <<~MSG + Notification to the Data Team about changes to files with possible impact on Data Warehouse, add label `Data Warehouse::Impact Check`. + + /label ~"Data Warehouse::Impact Check" + + The following files require a review: + + MSG + + DATA_WAREHOUSE_SCOPE = 'Data Warehouse::' + FILE_PATH_REGEX = %r{((ee|jh)/)?config/metrics(/.+\.yml)}.freeze + PERFORMANCE_INDICATOR_REGEX = %r{gmau|smau|paid_gmau|umau}.freeze + DATABASE_REGEX = %r{\Adb/structure\.sql}.freeze + STRUCTURE_SQL_FILE = %w(db/structure.sql).freeze + + def build_message + return unless impacted? + + CHANGED_SCHEMA_MESSAGE + helper.markdown_list(data_warehouse_impact_files) + end + + def impacted? + !labelled_as_datawarehouse? && data_warehouse_impact_files.any? + end + + private + + def data_warehouse_impact_files + @impacted_files ||= (performance_indicator_changed_files + database_changed_files) + end + + def labelled_as_datawarehouse? + helper.mr_labels.any? { |label| label.start_with?(DATA_WAREHOUSE_SCOPE) } + end + + def performance_indicator_changed_files + metrics_definitions_files = helper.modified_files.grep(FILE_PATH_REGEX) + + metrics_definitions_files.select do |file| + helper.changed_lines(file).any? { |change| change =~ PERFORMANCE_INDICATOR_REGEX } + end.compact + end + + def database_changes? + !helper.modified_files.grep(DATABASE_REGEX).empty? + end + + def database_changed_files + helper.modified_files & STRUCTURE_SQL_FILE + end + end + end +end diff --git a/tooling/danger/project_helper.rb b/tooling/danger/project_helper.rb index b49df50c5f0..f49b8bf7f2a 100644 --- a/tooling/danger/project_helper.rb +++ b/tooling/danger/project_helper.rb @@ -17,6 +17,7 @@ module Tooling product_intelligence utility_css vue_shared_documentation + datateam ].freeze CI_ONLY_RULES ||= %w[ diff --git a/tooling/deprecations/docs.rb b/tooling/deprecations/docs.rb deleted file mode 100644 index 0f649024b60..00000000000 --- a/tooling/deprecations/docs.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true -require 'erb' - -module Deprecations - module Docs - module_function - - def path - Rails.root.join("doc/update/deprecations.md") - end - - def render - deprecations_yaml_glob = Rails.root.join("data/deprecations/**/*.yml") - - source_files = Rake::FileList.new(deprecations_yaml_glob) do |fl| - fl.exclude(/example\.yml$/) - end - - deprecations = source_files.flat_map do |file| - YAML.load_file(file) - end - - deps = VersionSorter.sort(deprecations) { |d| d["removal_milestone"] } - - deprecations = deps.sort_by { |d| d["name"] } - - milestones = deps.map { |d| d["removal_milestone"] }.uniq - - template = Rails.root.join("data/deprecations/templates/_deprecation_template.md.erb") - - load_template(template) - .result_with_hash(deprecations: deprecations, milestones: milestones) - end - - def load_template(filename) - ERB.new(File.read(filename), trim_mode: '-') - end - end -end diff --git a/tooling/docs/deprecation_handling.rb b/tooling/docs/deprecation_handling.rb new file mode 100644 index 00000000000..7dfd3e1101d --- /dev/null +++ b/tooling/docs/deprecation_handling.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +require 'erb' + +module Docs + class DeprecationHandling + def initialize(type) + @type = type + @yaml_glob_path = Rails.root.join("data/#{type.pluralize}/**/*.yml") + @template_path = Rails.root.join("data/#{type.pluralize}/templates/_#{type}_template.md.erb") + @milestone_key_name = if type == "deprecation" + "announcement_milestone" + else + "removal_milestone" + end + end + + def render + source_file_paths = Rake::FileList.new(yaml_glob_path) do |fl| + fl.exclude(/example\.yml$/) + end + + entries = source_file_paths.flat_map do |file| + YAML.load_file(file) + end + entries = entries.sort_by { |d| d["name"] } + + milestones = entries.map { |entry| entry[milestone_key_name] }.uniq + milestones = VersionSorter.sort(milestones) + + load_template(template_path) + .result_with_hash(entries: entries, milestones: milestones) + end + + private + + def load_template(filename) + ERB.new(File.read(filename), trim_mode: '-') + end + + attr_reader :type, :yaml_glob_path, :milestone_key_name, :template_path + end +end |