Subversion hosting, CVS hosting, Trac hosting, Bugzilla hosting and software collaboration Providing hosted Subversion, CVS, Trac and Bugzilla repositories
 

February 22, 2008

Super-Configurable Subversion Notifications

Filed under: Source Code Control — Tags: , , , — Greg Larkin @ 8:13 pm

Hi everyone,

Are you using the Perl SVN::Notify module to generate your Subversion commit notification emails yet? If not, go install it, and try out svnnotify. It generates very nice-looking text or HTML-formatted emails, and it has loads of options to make it do just what you want. Place as many svnnotify commands as you like in your Subversion post-commit hook script, and off you go.

Unfortunately, with a large number of developers and many different projects in your repository, your post-commit script may start to look like this:

svnnotify -r $2 -d -P "SVN Commit " -O -H HTML::ColorDiff -p $1 -t dev@company.com
svnnotify -r $2 -H  Mirror::Rsync -p $1 --rsync-host devserver.company.com \
    --to /usr/local/www/htdocs --rsync-delete=yes
svnnotify -r $2 -d -P "SVN Tag Creation " -O -H HTML::ColorDiff -p $1 \
    -x builder@company.com=/tags
svnnotify -r $2 -d -P "SVN Branch Creation " -O -H HTML::ColorDiff -p $1 \
    -x builder@company.com=/branches
svnnotify -r $2 -d -P "SVN Vendor Drop " -O -H HTML::ColorDiff -p $1 \
    -x vendormgr@company.com=/vendor
svnnotify -r $2 -d -P "ClientA Special Version Commit " -O -H HTML::ColorDiff \
    -p $1 -x dev@clientA.com=/branches/clientA

Yikes -that’s bound to keep any Subversion administrator up nights! However, help is on the way from Perl developer John Peacock.

John has created a nice wrapper around SVN::Notify named SVN::Notify::Config. This Perl module transforms the mess of command lines above to a cleaner, easily-editable form using YAML to express the desired svnnotify options.

The equivalent post-commit hook using SVN::Notify::Config is now:

#!/usr/bin/perl -MSVN::Notify::Config=$0
 --- #YAML:1.0
 '':
   PATH: "/usr/bin:/usr/local/bin"
 '/':
   handler: HTML::ColorDiff
   with-diff:
   no-first-line:
   subject-prefix: "SVN Commit "
   to: dev@company.com
 '/':
   handler: Mirror::Rsync
   to: /usr/local/www/htdocs
   rsync-host: devserver.company.com
   rsync-delete: yes
 '/tags':
   handler: HTML::ColorDiff
   with-diff:
   no-first-line:
   subject-prefix: "SVN Tag Creation "
   to: builder@company.com
 '/branches':
   handler: HTML::ColorDiff
   with-diff:
   no-first-line:
   subject-prefix: "SVN Branch Creation "
   to: builder@company.com
 '/vendor':
   handler: HTML::ColorDiff
   with-diff:
   no-first-line:
   subject-prefix: "SVN Vendor Drop "
   to: vendormgr@company.com
 '/branches/clientA':
   handler: HTML::ColorDiff
   with-diff:
   no-first-line:
   subject-prefix: "ClientA Special Version Commit "
   to: dev@clientA.com



That’s a lot more readable, and I expect it will be easier to maintain, even though there are more lines in the file. I’m still boning up on the YAML syntax and how this module uses it, so there may be some optimizations to be made. Feel free to send corrections!

The other thing I like about using YAML this way is it lends itself well to hooking into a notification management web interface, and that makes it even easier to keep those emails flowing where they should.


Call me - Greg Larkin: error

Powered by WordPress