Skip to content

Instantly share code, notes, and snippets.

@stepheneb
Created August 31, 2009 21:36
Show Gist options
  • Save stepheneb/178728 to your computer and use it in GitHub Desktop.
Save stepheneb/178728 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# timesheet.rb <month to display>
#
# Displays a list of the subject lines for all commits by an author
# in one month. Defaults to the current month. You can specify a
# different month in many different ways.
#
# timesheet.rb last month
# timesheet.rb 1 => last January
# timesheet.rb jun => June
# timesheet.rb 1 year ago
#
# References:
#
# Chronic: A natural-language Time and Date parsing library:
# http://chronic.rubyforge.org/
#
# Man page doc for: git log
# http://www.kernel.org/pub/software/scm/git/docs/git-log.html
#
require 'rubygems'
require 'activesupport'
require 'chronic'
devroot = '/Users/stephen/dev/'
author = 'stephen'
repositories = [
['RITES', 'ruby/src/webapps/rigse2.git']
]
if ARGV.empty?
time = Time.now
else
time = Chronic.parse(ARGV.join(' '), :context => :past)
end
date_format = '%m/%d/%Y'
month_start = time.at_beginning_of_month.strftime(date_format)
time_month_end = time.next_month.at_beginning_of_month
if time_month_end > Time.now
time_month_end = Time.now
end
month_end = time_month_end.strftime(date_format)
repositories.each do |project, dir|
path = devroot + dir
Dir.chdir(path) do
commit_subjects = `git log HEAD --no-merges --reverse --since='#{month_start}' --until='#{month_end}' --pretty=format:"* %s%n" --author=#{author}`
commit_subjects.gsub!(/\n\n+\*/, "\n*")
puts <<HEREDOC
project: #{project}
repository: #{path}
author: #{author}
period: #{month_start} to #{month_end}
non-merge commits: #{commit_subjects.split("\n").length}
#{commit_subjects}
HEREDOC
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment