Skip to navigation [a]

April 2, 2007

RSS and Subversion for Mac OS X //

I’m not quite done with Subversion yet and have a few more tutorial-type entries planned over the next while provided the day-to-day comings and goings don’t get too much in the way along with finally getting an article I’ve been very, very slowly chipping away at (sorry Caroline!) for the last few months out the door and onto the editor’s desk.

That said, today I want to cover a simple nicety you can add to your Subversion install allowing you to more easily stay on top of incoming changes. This is particularly useful when more than one person has commit access to a project.

Subversion Commits via RSS
Monitor Subversion commits via RSS

Today we’re going to generate RSS output of changes being committed to Subversion. As usual, you’ll need your web browser, a text editor such as TextMate, and a Terminal window.

Getting Our Tools Together

To accomplish our goal of having an RSS or Atom-formatted XML file of repository changes output, the first thing we need to do is grab a copy of svn2feed.py, a hook script that will do the heavy lifting for us.

You can download svn2feed.py here (Right or Control-click and choose “Download Linked File” from the contextual menu).

Now that you have the file downloaded to your Desktop, using the Terminal, copy (or move) the file to the “hooks” directory in your repository. Using the example from the previous tutorials, let’s assume that is /usr/local/svn/.

Note that there’s a “hooks” directory in each versioned project, but also a global one for the repository itself which is the one we’re interested in.

sudo mv ~/Desktop/svn2feed.py /usr/local/svn/hooks/

Next, change the file permissions on the script to ensure it is executable.


sudo chmod ugo+x 
/usr/local/svn/hooks/svn2feed.py

Our script to do most of the work is now in place. Next we need to create a post-commit script which will be executed - you guessed it, after a user commits a change to Subversion.

Automating RSS

In this case, we’re only interested in generating a feed for one project in the repository. Using our previous example, let’s create a new file called post-commit in /usr/local/svn/metropolis_blog/hooks/ and open it in your preferred text editor.

Take the contents below and copy/paste it into your post-commit file.


#!/bin/sh

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

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

You can see the full documentation for what each of these items do in the svn2feed.py script, but the gist of it is that we’re telling the script to execute svn2feed.py using Python (which is installed by default on Mac OS X), keep the last 100 entries, use the Atom format, set the revision number based on the commit, set a permalink using the item-url, the full address of the feed itself via http, and where to actually save the XML file that gets output.

The REPOS variable is the path to your project in the repository.

Save the changes and close the file. We’re almost done.

Creating The Output Directory

Lastly, create the rss directory on your web server (eg. in /Library/WebServer/Documents) and make sure it is writeable by the script.

You’re now ready and can easily verify that everything is functioning by committing a change to the repository. If no XML file is output, odds are that the permissions are not set correctly. Assuming everything works as it should, simply subscribe to your RSS or ATOM feed and enjoy!

Before I forget, you might want to make sure Apache is running prior to attempting to subscribe to the feed ;-)

So say you…

Great, i have been meaning to start messing with svn but i could never find the time or motivation. These tutorials help heaps.

Karl Brightman Karl Brightman April 2, 2007

You might want to try the ChangeBlogger:

http://www.opengroupware.org/changeblogger/200703.html

Hum Bum Hum Bum April 2, 2007

When you get to the bottom you go back to the top of the slide… or check out our B-sides

It’s all interconnected …On A Long Piece Of String

Feeds //

Get social and don’t be a lurker

Elsewhere // Click to view

04