Skip to content

Instantly share code, notes, and snippets.

@bcardiff
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcardiff/20d5d9a5a9e069cb9e40 to your computer and use it in GitHub Desktop.
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
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
@bcardiff
Copy link
Author

You can execute this directly

$ curl -sSL http://man.as/TODOs | ruby

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment