Class: Codeowners::OwnerFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/codeowners/owner_finder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(codeowners_file:) ⇒ OwnerFinder

Returns a new instance of OwnerFinder.



13
14
15
# File 'lib/codeowners/owner_finder.rb', line 13

def initialize(codeowners_file:)
  @codeowners_file = codeowners_file
end

Class Method Details

.singletonObject



9
10
11
# File 'lib/codeowners/owner_finder.rb', line 9

def self.singleton(...)
  @singleton ||= new(...)
end

Instance Method Details

#find_owners_for_file(filepath:) ⇒ Array, <String>

Find the most likely owners of the file with the given filepath. Returns the owner name as an Array of Strings (e.g. [“card-1-be”, “card-2-be”])

Returns:

  • (Array, <String>)


20
21
22
23
24
25
# File 'lib/codeowners/owner_finder.rb', line 20

def find_owners_for_file(filepath:)
  last_matching_ownership = find_ownership_for_file(filepath:)
  return [] if last_matching_ownership.nil?

  last_matching_ownership.owners.map(&:to_s)
end

#find_ownership_for_file(filepath:) ⇒ Ownership

Find the most likely owners of the file with the given filepath. Returns

Returns:



29
30
31
32
33
# File 'lib/codeowners/owner_finder.rb', line 29

def find_ownership_for_file(filepath:)
  codeowners_file.ownerships_reversed.find do |ownership|
    ownership.glob_match?(filepath)
  end
end