Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created September 30, 2010 20:53
Show Gist options
  • Save seven1m/605303 to your computer and use it in GitHub Desktop.
Save seven1m/605303 to your computer and use it in GitHub Desktop.
Creates iCalendar (ical) format output containing commits from a Git repo.
#!/usr/bin/env ruby
# Creates iCalendar (ical) format output containing commits from a Git repo.
# Save as a file and import into Google Calendar or iCal on Mac.
# Publish on a webserver and link to Google Calendar directly.
# Install & Use:
# gem install grit icalendar
# chmod +x gitcal
# ./gitcal /path/to/repo > commits.ical
require 'rubygems'
require 'grit'
require 'icalendar'
require 'date'
require 'optparse'
include Grit
include Icalendar
options = {
:branch => 'master',
:count => 1000
}
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: gitcal [options] [repo path]\n" +
" gitcal [options] [repo path] > calendar.ical"
opts.separator ''
opts.on('-b', '--branch BRANCH', 'Specify repo branch (default "master")') do |b|
options[:branch] = b
end
opts.on('-c', '--count COUNT', 'Specify how many commits to include (default 1000)') do |c|
options[:count] = c
end
opts.on('-h', '--help', 'Show this help message.') do |h|
options[:show_help] = h
end
end
opt_parser.parse!
if options[:show_help]
puts opt_parser.help
puts
exit
end
cal = Calendar.new
repo = Repo.new(ARGV.first || '.')
repo.commits(options[:branch], options[:count]).each do |commit|
cal.event do
dtstart commit.authored_date.utc.strftime('%Y%m%dT%H%M%S')
dtend commit.authored_date.utc.strftime('%Y%m%dT%H%M%S')
summary commit.message
end
end
cal.publish
puts cal.to_ical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment