Last active
December 15, 2015 02:39
-
-
Save asross/5188948 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'time' | |
@default_root_dir = '~/code' # CHANGE THIS | |
def print_git_logs_since(date_str, root_directory) | |
logs_by_date_by_project = Hash.new{|h,k| h[k] = Hash.new{|h,k| h[k] =[]}} | |
root_directory ||= @default_root_dir | |
git_dirs = `find #{root_directory} -maxdepth 5 -type d -name .git -exec dirname {} \\;`.split("\n") | |
git_dirs.each do |dir| | |
directory = dir.split('/')[-1].strip | |
project = dir.split('/')[-2] | |
committer = `git config --global user.name`.strip | |
logs = `git --git-dir='#{dir}/.git' log --all --since=#{date_str} --author='#{committer}' --format=format:"%ad|||%s"`.split("\n") | |
STDOUT.puts "#{directory}: found #{logs.count} logs since #{date_str}" | |
logs.each do |log| | |
iso, message = log.split("|||") | |
time = Time.parse(iso) | |
date_string = time.strftime("%Y-%m-%d (%A)") | |
time_string = time.strftime("%I:%M %P") | |
logs_by_date_by_project[date_string][project] << ["#{time_string}, #{directory}: #{message}", time] | |
end | |
end | |
File.open("./commits-since-#{date_str}", 'w') do |f| | |
logs_by_date_by_project.keys.sort.each do |date| | |
f.write "--- #{date}:\n" | |
logs_by_date_by_project[date].each do |project, entries| | |
f.write "#{project}\n" | |
entries.uniq.sort_by{|e,t| t.to_i}.each do |entry, time| | |
f.write "#{entry}\n" | |
end | |
f.write "\n" | |
end | |
f.write "\n" | |
end | |
STDOUT.puts "printed summary to #{f.path}" | |
system "echo '#{f.path}' | pbcopy" | |
end | |
end | |
print_git_logs_since ARGV[0], ARGV[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment