Publish an RSS feed of Subversion commit messages
Teams that work together on the same files in a Subversion repository want a way to be notified when someone has committed updates. One way to do that is with an RSS feed; team members can all subscribe to the RSS feed and periodically check it.
Fortunately, Subversion allows you to define a command that will be run after a commit has completed. This is called the post-commit hook. We want to set our post-commit hook to be a script that maintains an RSS feed.
subverssed.py
The script we're going to use for our post-commit hook is called subverssed.py, a Python script. The source of this script is this article: SubveRSSed 1.0 on the Base-Art blog. The script you download from that page has a few bugs in it, so don't download that one. Download this one, instead: subverssed.py
The subverssed.py script depends on an XML library called EazeXML, maintained by the same author as that of subverssed.py. The appropriate version is 0.2.1, which exists only in the author's Subversion repository. If you want to get it the hard way:
svn co http://svn.base-art.net/public/easexml/trunk EaseXML-0.2.1 tar -z -c --exclude=.svn -f EaseXML-0.2.1 EaseXML-0.2.1
I've built an SRPM and tar.gz file of EaseXML for convenience:
Setup your repository files and directories
Now you need to set up your subversion repository appropriately. I use the Linux Standards Base naming scheme here, so change the following to fit your own naming scheme if necessary.
(as root) mkdir /svn/$hostname/subversion/bin cp subverssed.py /svn/$hostname/subversion/bin mkdir /svn/$hostname/subversion/feeds chown apache:apache /svn/$hostname/subversion/feeds
Prime the pump
We need to start subverssed.py off properly by reading in all the existing revisions and creating an RSS xml file of them.
(as root) /srv/$hostname/subversion/bin/subverssed.py -t "$repos_name" -r /srv/$hostname/subversion/$repos_name -o /srv/$hostname/subversion/feeds/ -l http://svn.caltech.edu/feeds/$repos_name chown -R apache:apache /srv/$hostname/subversion/feeds
Here, $repos_name is the name of this particular subversion repository. If, for instance, the URL to the repository is https://svn.foo.org/svn/foo, then $repos_name is "foo".
Setup the post-commit hook
Copy this to /srv/$hostname/subversion/$repos_name/hooks/post-commit, replacing $repos_name in the file appropriately.
#!/bin/sh # POST-COMMIT HOOK # # The post-commit hook is invoked after a commit. Subversion runs # this hook by invoking a program (script, executable, binary, etc.) # named 'post-commit' (for which this file is a template) with the # following ordered arguments: # # [1] REPOS-PATH (the path to this repository) # [2] REV (the number of the revision just committed) # # The default working directory for the invocation is undefined, so # the program should set one explicitly if it cares. # # Because the commit has already completed and cannot be undone, # the exit code of the hook program is ignored. The hook program # can use the 'svnlook' utility to help it examine the # newly-committed tree. # # On a Unix system, the normal procedure is to have 'post-commit' # invoke other programs to do the real work, though it may do the # work itself too. # # Note that 'post-commit' must be executable by the user(s) who will # invoke it (typically the user httpd runs as), and that user must # have filesystem-level permission to access the repository. # # On a Windows system, you should name the hook program # 'post-commit.bat' or 'post-commit.exe', # but the basic idea is the same. REV="$2" export PATH=/bin:/usr/bin /srv/__HOSTNAME__/subversion/bin/subverssed.py -t __REPOS_NAME__ -r /srv/__HOSTNAME__/subversion/__REPOS_NAME__ -o /srv/__HOSTNAME__/subversion/feeds/ -l http://__HOSTNAME__/feeds/__REPOS_NAME__ --revision "$REV"post-commit
Replace __HOSTNAME__ with the name of the host which will be the subversion server, as per our /srv directory naming scheme.
Replace __REPOS_NAME__ with what you used as $repos_name above.
Then do:
chown apache:apache /srv/$hostname/subversion/$repos_name/hooks/post-commit chmod a+x /srv/$hostname/subversion/$repos_name/hooks/post-commit
Subscribe to the RSS feed URL
The URL you will want to subscribe to is http://svn.foo.org/feeds/$repos_name.xml.
Testing your post-commit script
A.K.A. Why the hell doesn't it work?
Two things:
You must run the script as the apache user, because that's who will end up actually running the script.
- You must run it with an empty environment (no environment variables defined), because that's how Subversion will run your script.
(as root) cd /srv/$hostname/subversion/$repos_name/hooks chsh -s /bin/bash apache su apache -c "env - ./post-commit /srv/$hostname/subversion/$repos_name 1234"
See: Why aren't my repository hooks working? in the Subversion FAQ.

