Monday, June 05, 2006

Sending (mail) report after Subversion commit

Because of our former experience with version control systems like CVS or Subversion, in active multiuser development we needed to be notified by changes on certain projects changes. Subversion is our primary version control system and has built-in hooks functionality. Various scripts like pre-commit and post-commit are entrypoints for custom hooks.

So one of administration utilities developed by Seges is svnhooks set of hooks. This set contains utility svnreporter used to send reports after Subversion commit. Today supported way of sending is by email.

svnreporter is Java JAR utility which is managed through a simple configuration file. With this utility a sample post-commit script is provided. Installing it is simple as follows:
  1. copying post-commit script to Subversion hooks repository directory (for example /opt/your_repository/hooks)
  2. enabling execution of post-commit (like this - chmod 0755 post-commit)
  3. copying svnreporter Jar and libraries to a directory accessible by subversion
  4. setting variables in post-commit script - Java runtime executable, svnreporter Jar and configuration file location (Subvesion post-commit script doesn't inherit environment variables
  5. done :)
Of course Subversion has to be installed on your system. Simple configuration for a repository looks like this (svnreporter-repo1.conf):

reporter.type=mail

svn.svnlook.file = /usr/bin/svnlook

mail.smtp.host = localhost
mail.smtp.user = svnreporter
mail.smtp.password = supersecret

mail.from = test@mydomain.com
mail.to = admin@mydomain.com, guest@mydomain.com
mail.bcc = boss@mydomain.com


And post-commit looks like this:

#!/bin/sh

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

SVNReporterDir="/opt/svnreporter"
#SVNReporterConf is specific to your repository
SVNReporterConf="$SVNReporterDir/svnreporter-repo1.conf"
SVNReporterJar="$SVNReporterDir/svnreporter.jar"
JAVA="/opt/java/jre/bin/java"

$JAVA -jar $SVNReporterJar -r "$REPOS" -R "$REV" -c $SVNReporterConf


If you want to see some log use -f argument on last line.

Well and that's your brand new mail report notification. More svnhooks utilities will come and if you have any ideas there is no broader space for solutions ;)

No comments: