HOWTO: Adding an RSS feed to a Subversion Server

I have now gone on stage twice and talked about how useful an RSS feed is for a subversion server. About time I actually document how to set up such a thing.

This tutorial will start by creating a local subversion server. The rest of the directions are universally applicable with the caveat that you need to make sure that the user running the RSS generation actually has write access to wherever the RSS feed(s) are to be written.

Of course, this all assumes Mac OS X. It would only require a bit of modification to make this work on any random Unix derivative and a slight bit more for Windows.

You’ll need to have a Subversion package installed that includes the server bits. I typically grab the bits from darwinports or http://fink.sourceforge.net/. Wilfredo Sanchez’s iDisk has prebuilt bits, too.

Create a Local Subversion Repository

The following command line will create a subversion repository at the given path.

svnadmin create --fs-type fsfs /Volumes/Data/svn

Grab the Necessary RSS Generation Scripts

From Dalke Scientific’s Python page, you’ll need to grab PyRSS2Gen (tarball).

Copy this to the hooks directory of the repository. In my case:

cp PyRSS2Gen.py /Volumes/Data/svn/hooks/

Grab svn2feed.py from the Subversion subversion repository’s contributed hooks directory.

cd /Volumes/Data/svn/hooks/
curl -O http://svn.collab.net/repos/svn/trunk/contrib/hook-scripts/svn2feed.py

Setup the Commit Hook to Generate RSS on Commit

cd /Volumes/Data/svn/hooks/
# copy the code below
pbpaste > post-commit
chmod a+x post-commit

This is the contents of the RSS feed only post-commit.

#!/bin/sh

REPOS="$1"
REV="$2"

/usr/bin/python /Volumes/Data/svn/hooks/svn2feed.py 
    --svn-path /usr/bin/ 
    --max-items=100 
    --format=atom 
    --revision "$REV" --item-url "http://localhost/svn/" 
    --feed-url="http://localhost/rss/svn.rss" 
    --feed-file "/Library/WebServer/Documents/rss/svn.rss" 
    "$REPOS" &

See the svn2feed.py usage and documentation for more information on what all the parameters actually mean.

Update: Fitz made fun of me for not including the & at the end. The post-commit hook doesn’t care about the exit codes of sub-commands and, therefore, there is no reason to make the user wait for the execution of the various commands.

python svn2feed.py --help

Setup the RSS Directory on the WebServer

This is where the permissions can be tricky. In the following, it is configured to allow read/write by anyone. Solves the permissions problem while completely sacrificing security in that directory. A better solution would be to make the directory owned by and writable by whatever user executes the svn2feed.py script; typically, the web server’s user when using svn-via-http. For non-HTTP svn servers, the directory will likely have to be group writable with the setGID bit set as the “server” side of svn may be executed as different users.

sudo mkdir /Library/WebServer/Documents/rss
sudo chown nobody /Library/WebServer/Documents/rss
sudo chmod a+rwx /Library/WebServer/Documents/rss

Notes

That should be it. It should “just work”.

But, of course, it probably won’t. To troubleshoot, go to the hooks/ directory in a terminal and copy/paste the svn2feed.py command line above. Fill the $REV and $REPOS variables as appropriate and execute the command.

Keep futzing with that until it generates something useful.

Then plug the result back into post-commit and try executing a transaction against the subversion repository. If the feed doesn’t update, it is most likely because there is something different about the execution environment within subversion vs. the user shell.

Since there isn’t a log file generated by the execution of the post-commit script, add “ &> /tmp/munch.log” after the "$REPOS" (but before the & to (hopefully) log some useful diagnostics into /tmp/munch.log.

The formatting of the resulting feed is really really ugly in both NetNewsWire and Safari.

Ugly enough that I couldn’t stand it. Grab svn2feed.py from my subversion repository and see if it works better for you.

It does for me in NetNewsWire, but I’m finding that Safari’s feed caching makes testing difficult. As well, the HTML entities seem to leak into Safari’s output whereas NNW renders them “correctly” (where “correctly” is, in the classic ambiguous HTML sense of the words, defined as “looks good enough for me, HTML definition be damned”).

Forgot to mention: Patches are assuredly welcome!



5 Responses to “HOWTO: Adding an RSS feed to a Subversion Server”

  1. Dominik Wagner says:

    Of course you could just get a hosted account at versionshelf which will start business next week.

    Or also, which is quite simple, grab svnxslt by martin from map’s portfolio which uses xsltproc instead of python. Much more appropriate if you ask me, since svn already emits xml.

  2. bbum says:

    Except that I don’t want stuff on my local machine hosted anywhere but my local machine, nor do many companies want their code hosted at an external site, quality of service guarantee be damned.   Versionshelf looks quite cool, though, if a project falls into the set of projects that can be hosted at such a service.

    Seems like a bit of overkill to fire up an XSLT transformation engine against svn generated XML to spew the feed in comparison to just dumping the RSS/Atom DOM directly based on svn generated plain text.   Neat solution and all, but I fail to see any significant advantage over the somewhat mediocre solution I outlined.

  3. Dominik Wagner says:

    I understand your concerns. But I know I would have been more than happy if such a service would have been around just for my freelance work. Setting up your own secure server isn’t a piece of cake. You’ll have to manage a dedicated server to keep everyone else out, if you do that already, versionshelf won’t be of much interest, of course. Regarding having code only on my local machine: I on the other hand take comfort in the fact that if my local machine breaks and my backups haven’t been the best (maybe that will change with Time Machine) my code still is intact. But I’m glad that you don’t deleted my shameless plug right away.

    As rss generation goes: If xsltproc is available (which it is on mac os x) I just think of xslt as a much cleaner solution. But that’s just me, and maybe I’m to anal about this ;) . But running a xslt transformation engine isn’t so much more overkill than running a python script, IMHO.

  4. inkBlots » RSS for Subversion and Dreamweaver says:

    […] Here’s a nifty article on how to set up an RSS feed for your subversion server. One caveat, though: “Of course, this all assumes Mac OS X. It would only require a bit of modification to make this work on any random Unix derivative and a slight bit more for Windows.” […]

  5. Daniel J. Luke says:

    trac (http://trac.edgewall.org/) can also be used to generate rss feeds of your svn repository.

    It’s meant to be more than just a feed generator, though, so it’s much more heavyweight.

    (but it’s also available from darwinports).

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>