Skip to content

Instantly share code, notes, and snippets.

@defunkt
Forked from dchest/log2icalendar.rb
Created May 18, 2009 23:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save defunkt/113812 to your computer and use it in GitHub Desktop.
Save defunkt/113812 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:
#
# cd git-repo
# log2icalendar.rb > outfile.ics
#
require 'date'
puts "BEGIN:VCALENDAR"
puts "VERSION:2.0"
puts "PRODID:-//hacksw/handcal//NONSGML v1.0//EN"
event_started = false
IO.popen("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