Skip to content

Instantly share code, notes, and snippets.

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")
.map { |s| glob, names = s.split(/\s+/, 2)
glob += "*" if glob.end_with? "/"
[glob, names]
.reverse # more specific is last in the file
paths = `git diff --name-only master..`
paths = `git diff --name-only .`
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
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.