Skip to content

Instantly share code, notes, and snippets.

@swistak
Last active December 19, 2015 06:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swistak/5909035 to your computer and use it in GitHub Desktop.
Save swistak/5909035 to your computer and use it in GitHub Desktop.
Working bee.
# Helpful reference http://alexpeattie.com/blog/working-with-dates-in-git/
require 'date'
require 'pp'
cmd="git log --author='#{ARGV[0]}' --abbrev-commit --format=medium --date=iso"
cmd+= " --since=#{Date.parse(ARGV[1]).to_s}" if ARGV[1]
cmd+= " --until=#{Date.parse(ARGV[2]).to_s}" if ARGV[2]
e = e = <<GIT
commit eca3dae
Author: Marcin Raczkowski <marcin.raczkowski@gmail.com>
Date: 2013-06-03 18:46:29 +0200
Adding default ordering for content_parts
GIT
puts cmd
commits = `#{cmd}`
commit = nil
author = nil
date = nil
desc = []
by_date = Hash.new{|h,k| h[k] = []}
since = Date.today
commits.split(/\n/).each do |line|
case line
when /^commit (\w+)/
if commit
since = date if since > date
by_date[date] << {commit: commit, author: author, date: date, desc: desc}
author = nil; date = nil; desc = []
end
commit = $1
when /^Author: (.+)/
author = $1
when /^Date: (.+)/
date = Date.parse($1)
else
if commit
desc << line
end
end
end
(since..Date.today).each do |cdate|
if cdate.wday == 0 || cdate == since # Sunday
# Week adjustment is of course working only for 2013 and 9 is a week of start of project.
# needs to be adjusted per project of course.
puts "=== Week: #{(cdate.yday - 6) / 7 - 9}"
end
if (cs = by_date[cdate]) && cs.length > 0
puts cdate.strftime("%Y-%m-%d %A") + " - #{cs.length} commits"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment