-
-
Save forkrul/9173291 to your computer and use it in GitHub Desktop.
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
#! /usr/bin/env ruby | |
# encoding: UTF-8 | |
require 'date' | |
since = ARGV.shift || Date.today | |
logs = `git log --since="#{since}" --pretty=format:"%H,%ae,%ai"` | |
all_commits = logs.split("\n").map{|i| i.split(",") } | |
if all_commits.empty? | |
puts "No commits found since #{since}" | |
exit | |
end | |
def parse_time(time) | |
DateTime.parse(time).to_time | |
end | |
def get_hours(commits) | |
t1 = parse_time(commits.first[2]) | |
t2 = parse_time(commits.last[2]) | |
((t1 - t2) / 3600).round(3) | |
end | |
def stats_for(label, commits) | |
indent = " " * (20 - label.length).abs | |
hours = get_hours(commits) | |
print "#{indent}#{label}:\t" | |
print hours | |
print " hours" | |
puts | |
end | |
stats_for("Total", all_commits) | |
all_commits.group_by{|i| i[1] }.each do |user, user_commits| | |
stats_for(user, user_commits) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment