Class: Datadog::CI::Codeowners::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/ci/codeowners/parser.rb

Overview

Responsible for parsing a CODEOWNERS file

Constant Summary collapse

DEFAULT_LOCATION =
"CODEOWNERS"
POSSIBLE_CODEOWNERS_LOCATIONS =
%w[
  CODEOWNERS
  .github/CODEOWNERS
  .gitlab/CODEOWNERS
  docs/CODEOWNERS
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(root_file_path) ⇒ Parser

Returns a new instance of Parser.



18
19
20
# File 'lib/datadog/ci/codeowners/parser.rb', line 18

def initialize(root_file_path)
  @root_file_path = root_file_path || Dir.pwd
end

Instance Method Details

#parseObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/datadog/ci/codeowners/parser.rb', line 22

def parse
  default_path = File.join(@root_file_path, DEFAULT_LOCATION)
  # We are using the first codeowners file that we find or
  # default location if nothing is found
  #
  # Matcher handles it internally and creates a class with
  # an empty list of rules if the file is not found
  codeowners_file_path = POSSIBLE_CODEOWNERS_LOCATIONS.map do |codeowners_location|
    File.join(@root_file_path, codeowners_location)
  end.find do |path|
    File.exist?(path)
  end || default_path

  ::Datadog.logger.debug { "Using CODEOWNERS file from: #{codeowners_file_path}" }

  Matcher.new(codeowners_file_path)
end