Sha256: 6cc33d90b82761e4873fb9a06fd79163a117a81af7c9f531af0988d9c972498e

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require_relative "matcher"

module Datadog
  module CI
    module Codeowners
      # Responsible for parsing a CODEOWNERS file
      class Parser
        DEFAULT_LOCATION = "CODEOWNERS"
        POSSIBLE_CODEOWNERS_LOCATIONS = %w[
          CODEOWNERS
          .github/CODEOWNERS
          .gitlab/CODEOWNERS
          docs/CODEOWNERS
        ].freeze

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

        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
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
datadog-ci-1.11.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.10.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.9.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.8.1 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.8.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.7.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.6.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.5.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.4.1 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.4.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.3.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.2.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.1.0 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.0.1 lib/datadog/ci/codeowners/parser.rb
datadog-ci-1.0.0 lib/datadog/ci/codeowners/parser.rb