Skip to content

Instantly share code, notes, and snippets.

@zackdouglas
Forked from ryanflorence/gitrss.rb
Created April 8, 2014 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zackdouglas/10159250 to your computer and use it in GitHub Desktop.
Save zackdouglas/10159250 to your computer and use it in GitHub Desktop.
# Adapted by Ryan Florence (http://ryanflorence.com)
# original by Chris Dinger: http://www.houseofding.com/2009/03/create-an-rss-feed-of-your-git-commits/
#
# Takes one, two, or three arguments
# 1. Repository path (required) - the path to the repository
# 2. The url to put as the <link> for both channel and items
# 3. the repository name, defaults to directory name of the repository
#
# Command line usage:
# ruby gitrss.rb /path/to/repo > feed.rss
# ruby gitrss.rb /path/to/repo http://example.com > feed.rss
# ruby gitrss.rb /path/to/repo http://example.com repo_name > feed.rss
repository_path = $*[0]
url = $*[1] || 'http://example.com/rss/'
Dir.chdir repository_path
repository_name = $*[2] || `pwd`.split('/').last.chop
git_history = `git log --max-count=10 --name-status`
entries = git_history.split("\ncommit ")
rss = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<rss version=\"2.0\">
<channel>
<title>#{repository_name} commits</title>
<description>Git commits to #{repository_name}</description>
<link>#{url}</link>
<lastBuildDate>#{Time.now}</lastBuildDate>
<pubDate>#{Time.now}</pubDate>
"
entries.each do |entry|
guid = entry.gsub(/^.*commit /ms, '').gsub(/\n.*$/ms, '')
author_name = entry.gsub(/^.*Author: /ms, '').gsub(/ <.*$/ms, '')
date = entry.gsub(/^.*Date: +/ms, '').gsub(/\n.*$/ms, '')
comments = entry.gsub(/^.*Date[^\n]*/ms, '')
rss += "
<item>
<title>Commit by #{author_name}</title>
<description>#{author_name} made a commit on #{date}</description>
<content><![CDATA[
<table border=0>
<tr><td align=right><b>SHA</b></td><td>#{guid}</td></tr>
<tr><td align=right><b>Author</b></td><td>#{author_name}</td></tr>
<tr><td align=right><b>Date</b></td><td>#{date}</td></tr>
</table>
<pre>#{comments}</pre>
]]></content>
<link>#{url}</link>
<guid isPermaLink=\"false\">#{guid}</guid>
<pubDate>#{date}</pubDate>
</item>"
end
rss += "
</channel>
</rss>"
puts rss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment