Skip to content

Instantly share code, notes, and snippets.

@denis
Forked from dchest/log2icalendar.rb
Created April 14, 2009 17:56
Show Gist options
  • Save denis/95316 to your computer and use it in GitHub Desktop.
Save denis/95316 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Git log to iCalendar
#
# Written by Dmitry Chestnykh, 5 Aug 2008
# Public domain
#
# Usage:
#
# log2icalendar.rb path-to-git-repo > outfile.ics
#
require 'date'
puts "BEGIN:VCALENDAR"
puts "VERSION:2.0"
puts "PRODID:-//hacksw/handcal//NONSGML v1.0//EN"
puts "X-WR-CALNAME:Podcasts"
event_started = false
IO.popen("cd #{ARGV[0]}; git log","r").each do |line|
if line =~ /Date:/
date_str = line.scan(/Date:(.*)/)[0][0]
date = DateTime.parse(date_str, '%a %-d %b %Y %T %z')
# print event
puts "\nEND:VEVENT" if event_started
event_started = true
puts "BEGIN:VEVENT"
puts "DTSTART:" + date.strftime("%Y%m%dT%H%M%S")
puts "DTEND:" + date.strftime("%Y%m%dT%H%M%S")
print "SUMMARY:"
elsif line =~ /[ ]{4}/ # commit message after 4 spaces
print line.strip.gsub(/([;,\\\\])/, '\\\\\\1')
end
end
puts "\nEND:VEVENT"
puts "END:VCALENDAR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment