Follow-up from "Require Product Intelligence reviews for frontend Snowplow events"

The following discussion from !54273 (merged) should be addressed:

  • @splattael started a discussion:

    Non-blocking idea I had one idea how to make future pattern additions easier and more obvious and came up with the following structure:

    ANY_CHANGE = Object.new
    
    FILE_CHANGES = {
      tracking: {
        'lib/gitlab/tracking.rb' => ANY_CHANGE
        'spec/lib/gitlab/tracking_spec.rb' => ANY_CHANGE,
        'app/helpers/tracking_helper.rb' => ANY_CHANGE,
        'spec/helpers/tracking_helper_spec.rb' => ANY_CHANGE,
        'app/assets/javascripts/tracking.js' => ANY_CHANGE,
        'spec/frontend/tracking_spec.js' => ANY_CHANGE,
        'generator_templates/usage_metric_definition/metric_definition.yml' => ANY_CHANGE,
        'lib/generators/rails/usage_metric_definition_generator.rb' => ANY_CHANGE,
        'spec/lib/generators/usage_metric_definition_generator_spec.rb' => ANY_CHANGE,
        'config/metrics/schema.json' => ANY_CHANGE
      }
      usage_data: {
        /usage_data/ => ANY_CHANGE,
      }
      metrics: {
        %r{config/metrics/.*\.yml} => ANY_CHANGE,
      },
      metrics_dictionary: {
        'doc/development/usage_ping/dictionary.md' => ANY_CHANGE,
      },
      snowplow: {
        /\.rb$/ => /Gitlab::Tracking\.event/,
        /\.(js|vue)$/ => Regexp.union(
          'Tracking.event',
          /\btrack\./,
          'data-track-event'
        ),
        /\.haml$/ => %r{\b(event|track)\b}
      },
    }
    
    changed_files = determine_changed_files(all_changed_files)
    # returns a Hash: <section> => [<file>, ...]
    # Example: { tracking: ['lib/gitlab/tracking.rb', ...], metrics: [ ... ] }
    

    changed_files then could be used below like:

    matching_changed_files = changed_files.flatten(1)
    
    if matching_changed_files.any?
      mention = if helper.draft_mr?
                  "`#{ENGINEERS_GROUP}`"
                else
                  ENGINEERS_GROUP
                end
    
      warn format(CHANGED_FILES_MESSAGE, changed_files: helper.markdown_list(matching_changed_files), engineers_group: mention)
      warn format(UPDATE_METRICS_DEFINITIONS_MESSAGE) if changed_files.key?(:metrics)
    
      fail format(UPDATE_DICTIONARY_MESSAGE) if changed_files.key?(:metrics) && changed_files.key?(:metrics_dictionary)
    
      labels = ['product intelligence']
      labels << 'product intelligence::review pending' unless helper.mr_has_labels?('product intelligence::approved')
    
      markdown(helper.prepare_labels_for_mr(labels))
    end

    WDYT of this approach? Would this make adding patterns in the future easier? 🤔

    Again, not this MR and just an idea but happy to collaborate on this if you like this idea!