module Owners

Constants

VERSION

Attributes

file[W]

@api public

Public Class Methods

file() click to toggle source

The name of the file used to store ownership subscriptions. Defaults to OWNERS.

@api public

   # File lib/owners.rb
23 def file
24   @file ||= "OWNERS"
25 end
for(*files) click to toggle source

Accepts a list of file paths and returns an array of owners that have subscribed to the specified files.

@api public

   # File lib/owners.rb
31 def for(*files)
32   Search.new(files).owners
33 end
for_diff(ref, base = "master") click to toggle source

Accepts a git ref and an optional base ref and returns an array of owners that have subscribed to the changes.

The base ref defaults to “master”.

@api public

   # File lib/owners.rb
41 def for_diff(ref, base = "master")
42   files = `git diff --name-only #{base}...#{ref}`.split("\n")
43 
44   # TODO: why doesn't this work? It works in the command line...
45   # blobs = `git ls-tree -r #{ref} | **/#{file}`.split("\n")
46   blobs = `git ls-tree -r #{ref} | egrep "(^|/)#{file}$"`.split("\n")
47 
48   configs = blobs.reduce({}) do |hash, line|
49     _, _, sha, file = line.split(/\s+/, 4)
50     contents = `git show #{sha}`
51     hash.update(file => contents)
52   end
53 
54   Search.new(files, configs).owners
55 end
missing_for(*files) click to toggle source

Accepts a list of file paths and returns an array of the ones that do not have subscribed owners.

@api public

   # File lib/owners.rb
61 def missing_for(*files)
62   paths = Search.new(files, shallow: true).paths
63   files - paths
64 end