Last active
December 13, 2019 16:43
-
-
Save gmcculloug/f0b3621137c3ac78ed6edab818cff342 to your computer and use it in GitHub Desktop.
List code owners
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def walk(start = ".", prefix = "") | |
Dir.foreach(start) do |x| | |
next if x[0] == "." | |
path = File.join(start, x) | |
next if File.symlink?(path) | |
print_directory(path, prefix) if File.directory?(path) | |
end | |
end | |
def print_directory(path, prefix) | |
owners = direct_owners(path) | |
if owners.size > 0 | |
puts "#{prefix}#{path}" + "/" # remove this line if you want; just prints directories | |
print_owners(owners, prefix) | |
puts | |
walk(path, prefix + " ") | |
end | |
end | |
def print_owners(owners, prefix) | |
owners.each { |o| puts "#{prefix} #{o}" } | |
end | |
def direct_owners(path, limit: nil, user_count: 5) | |
owners = `git log --pretty=format:"%an%x09" #{path} | sort | uniq -c | sort -n -r`.split("\n") | |
owners = owners.take(limit) if limit | |
owners.reject! { |o| o.to_i < user_count } | |
owners | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment