Class: Datadog::CI::Codeowners::Matcher
- Inherits:
-
Object
- Object
- Datadog::CI::Codeowners::Matcher
- Defined in:
- lib/datadog/ci/codeowners/matcher.rb
Overview
Responsible for matching a test source file path to a list of owners
Instance Method Summary collapse
-
#initialize(codeowners_file_path) ⇒ Matcher
constructor
A new instance of Matcher.
- #list_owners(file_path) ⇒ Object
Constructor Details
#initialize(codeowners_file_path) ⇒ Matcher
Returns a new instance of Matcher.
10 11 12 13 |
# File 'lib/datadog/ci/codeowners/matcher.rb', line 10 def initialize(codeowners_file_path) @rules = parse(codeowners_file_path) @rules.reverse! end |
Instance Method Details
#list_owners(file_path) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/datadog/ci/codeowners/matcher.rb', line 15 def list_owners(file_path) # treat all file paths that we check as absolute from the repository root file_path = "/#{file_path}" unless file_path.start_with?("/") Datadog.logger.debug { "Matching file path #{file_path} to CODEOWNERS rules" } @rules.each do |rule| if rule.match?(file_path) Datadog.logger.debug { "Matched rule [#{rule.pattern}] with owners #{rule.owners}" } return rule.owners end end Datadog.logger.debug { "CODEOWNERS rule not matched" } nil end |