Refactor pattern match code for CI rules:changes code

Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.

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

  • @splattael started a discussion:

    If this approach is accepted, we could consider refactoring this code to streamline multiple match kinds, for example:

      class Match
        def match?(paths, globs)
          raise NotImplementedError
        end
    
        def self.consider?(glob)
          raise NotImplementedError      
        end
      end
    
      class ExactMatch < Match
        def match?(paths, globs)
          globs.any? do |glob|
            paths.bsearch { |path| glob <=> path }
          end
        end
    
        def self.consider?(glob)
          !glob.include?('*') && !glob.include?('?') && !glob.include?('[') && !glob.include?('{')
        end
      end
    
      class PatternMatch < Match
        def match?(paths, globs)
          comparisons = 0
    
          globs.any? do |glob|
            paths.any? do |path|
              comparisons += 1
              comparisons > MAX_PATTERN_COMPARISONS || pattern_match?(glob, path)
            end
          end
        end
    
        # Fallback
        def self.consider?(glob)
          true
        end
      end
Edited by 🤖 GitLab Bot 🤖