Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env ruby -ws
$y ||= false
require "pp"
abort "need a commit message" if ARGV.empty?
msg = ARGV.join " "
owners = File.readlines(".github/CODEOWNERS")
.grep_v(/^#/)
.map(&:chomp)
.map { |s| glob, names = s.split(/\s+/, 2)
glob += "*" if glob.end_with? "/"
[glob, names]
}
.reverse # more specific is last in the file
.to_h
paths = `git diff --name-only master..`.lines.map(&:chomp)
paths = `git diff --name-only .`.lines.map(&:chomp)
unowned = File.readlines("test/files/unowned.txt").map(&:chomp) & paths
owned = paths - unowned
owned.group_by { |path|
owners.find { |glob, names| File.fnmatch(glob, path) }.last
}.each do |names, files|
puts "git commit -m %p %s" % ["#{msg} (#{names})", files.join(" ")]
system "git", "commit", "-m", "#{msg} (#{names})", *files if $y
end
puts "git commit -m %p %s" % ["#{msg} (unowned)", unowned.join(" ")]
system "git", "commit", "-m", "#{msg} (unowned)", *unowned if $y
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.