Subversion: Emailing users on commit

Alex gave me a script the other day to email users when someone commits a change to a svn repository, and I expanded on it a bit to use a subroutine for the actual notification and include the repository name in the URL. Nothing fancy (at all), but I thought I'd share.

You'll need to download and install SVN-Notify for this to work. If you have root access the easiest way is by using CPAN.

# perl -MCPAN -e shell
...
cpan[1]> i /SVN-Notify/
...
Distribution    DWHEELER/SVN-Notify-2.66.tar.gz
...
4 items found
 
cpan[2]> install DWHEELER/SVN-Notify-2.66.tar.gz

Next edit repository/hooks/post-commit and use the following script as your starting point. Make sure to make the file executable (chmod +x hooks/post-commit).

#!/bin/bash
 
#################
# Config        #
#################
 
NOTIFY_LIST="email@address1 email@address2 email@address3"
SVNNOTIFY="/usr/local/bin/svnnotify"
FROM="Display Name <svn_reply_to_addr@domain.tld>"
REPLY_TO="$FROM"
 
################
# End Config   #
################
 
 
REPOS="$1"
REV="$2"
REPOS_NAME=`echo $REPOS | sed 's/[^\/]*\///g'`
 
################
# Subroutines  #
################
 
notify() {
  $SVNNOTIFY                           \
    --repos-path      "$REPOS"         \
    --revision        "$REV"           \
    --subject-cx                       \
    --subject-prefix  "$REPOS_NAME - " \
    --with-diff                        \
    --handler         HTML::ColorDiff  \
    --to              "$1"             \
    --from            "$FROM"          \
    --reply-to        "$FROM"
}
 
 
#################
# Body          #
#################
 
for foo in $NOTIFY_LIST ; do
 notify "$foo"
done

 

4 Responses to “Subversion: Emailing users on commit”

  1. Links for Tue 21 Aug 2007 through Tue 28 Aug 2007 | Joseph Scott's Blog Says:

    [...] Subversion: Emailing users on commit | corey gilmore's blog – Expanding on sending commit notifications from Subversion via email. Tags: subversion email [...]

  2. Get Subversion Updates via Email | Slaptijack Says:

    [...] Update: Corey Gilmore apparently had the same brainwave about a week before I did: Subversion: Emailing users on commit. [...]

  3. Daniel J. Doughty Says:

    Hi Corey,

    I'm trying to get this set up for a group of developers. Unfortunately I seem to be missing something. The emails go out, but there is almost nothing in the content. The author field isn't populated, the diff doesn't show, etc. I tried changing the –with-diff flag to -attach-diff but that didn't really make any difference. I mean, the diff is still empty, only now it's attached.

    This is on Solaris 10.

    It appears that Subversion is passing the correct variables, as I echoed them out to a temp file during one of the commits and here are REPOS, REV and REPOS_NAME:

    /data/svn/testRepository
    11
    testRepository

    Executing the raw command from the command line yielded this:

    # /usr/perl5/5.8.4/bin/svnnotify –repos-path /data/svn/testRepository –revision 11 –subject-cx –subject-prefix "testRepository – " –attach-diff –handler HTML::ColorDiff –to red@act.ed –from "Subversion" –reply-to "Subversion"
    Use of uninitialized value in exec at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Can't exec "": No such file or directory at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Use of uninitialized value in concatenation (.) or string at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Cannot exec : No such file or directory
    Child process exited: 512
    Use of uninitialized value in exec at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Can't exec "": No such file or directory at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Use of uninitialized value in concatenation (.) or string at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Cannot exec : No such file or directory
    Child process exited: 512
    Use of uninitialized value in exec at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Can't exec "": No such file or directory at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Use of uninitialized value in concatenation (.) or string at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Cannot exec : No such file or directory
    Use of uninitialized value in substitution (s///) at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 1239.
    Use of uninitialized value in substitution (s///) at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 1240.
    Child process exited: 512
    Use of uninitialized value in index at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 1309.
    Use of uninitialized value in concatenation (.) or string at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 1310.
    Use of uninitialized value in substitution (s///) at (eval 6) line 1.
    Use of uninitialized value in print at /usr/perl5/site_perl/5.8.4/SVN/Notify/HTML.pm line 323.
    Use of uninitialized value in print at /usr/perl5/site_perl/5.8.4/SVN/Notify/HTML.pm line 323.
    Use of uninitialized value in substitution (s///) at (eval 6) line 1.
    Use of uninitialized value in print at /usr/perl5/site_perl/5.8.4/SVN/Notify/HTML.pm line 326.
    Use of uninitialized value in print at /usr/perl5/site_perl/5.8.4/SVN/Notify/HTML.pm line 326.
    Use of uninitialized value in exec at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Can't exec "": No such file or directory at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Use of uninitialized value in concatenation (.) or string at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 2309.
    Cannot exec : No such file or directory
    Use of uninitialized value in concatenation (.) or string at /usr/perl5/site_perl/5.8.4/SVN/Notify.pm line 1697.
    Child process exited: 512

    Any ideas?

  4. Corey Says:

    Hey Daniel,

    Try quoting the repository name too:

    /usr/local/bin/svnnotify  --repos-path "/data/svn/testRepository" --revision "11" --subject-cx --subject-prefix "testRepository - " --with-diff --handler HTML::ColorDiff --to "you@yourdomain.com" --from "you@yourdomain.com" --reply-to "you@yourdomain.com"

    The only other change I see is that you were attaching the diff. Also check out line 2309 in /usr/perl5/site_perl/5.8.4/SVN/Notify.pm, it looks like it's searching for a file that isn't found.

Leave a Reply


© 2007-2010, Corey Gilmore | Posts RSS Feed | Comments RSS Feed | Contact

 

The views expressed on these pages are mine alone and not those of any past or present employer. All information presented on this site was obtained lawfully and not through disclosure under the terms of an NDA.