Last active
August 29, 2015 14:14
-
-
Save bcardiff/20d5d9a5a9e069cb9e40 to your computer and use it in GitHub Desktop.
List of TODOs in ./app/ decorated with blame sorted by time git grep blame
This file contains hidden or 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
require 'date' | |
target = ARGV[1] || "." | |
files = %x(git grep -n 'TODO*' #{target}) | |
lines = [] | |
length_author = 0 | |
length_file = 0 | |
files.each_line do |line| | |
m = line.match(/([^:]*):(\d+):(.*)/) | |
l = { | |
path: m[1], | |
num: m[2], | |
msg: m[3].strip | |
} | |
length_file = [length_file, l[:path].length + l[:num].length + 1].max | |
blame = %x(git blame -p -L #{l[:num]},+1 #{l[:path]}) | |
blame.each_line do |bline| | |
if m = bline.match(/^author\s(.*)$/) | |
l[:author] = m[1] | |
length_author = [length_author, l[:author].length].max | |
elsif m = bline.match(/^author\-time\s(\d+)$/) | |
l[:datetime] = DateTime.strptime(m[1],'%s') | |
end | |
end | |
lines << l | |
end | |
lines.sort_by!{ |l| l[:datetime] }.reverse! | |
lines.each do |l| | |
path_num = "#{l[:path]}:#{l[:num]}" | |
puts "(#{l[:datetime].to_date} #{l[:author].ljust(length_author)}) #{path_num.ljust(length_file)} #{l[:msg]}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can execute this directly