2009-02-12

Using mailer.py to send SVN Commit Notificaiton Email

Yesterday when I tried to find a way to get the SVN server send out an email whenever there is a commit, I first came across commit-email.pl via Google. But it turned out that script is deprecated and the newer/cooler version is mailer.py. However there is not so much information on how to use the latter although it is not so complicated, so here is a quick note.

To get the script, there is a package in the repo called subversion-tools, it will install a couple of scripts inside /usr/share/subversion/hook-scripts/ and one of them is mailer.py.

mailer.py needs an configuration file, and if not specified, it will search for a file called mailer.conf in your svn repo’s conf folder. You can find an example configuration file inside the same folder where the mailer.py script stays. I copied that example to /var/svn/repos/conf/ (you may want to change it to match your svn repo path) and changed the content to match the setting I prefer. There are plenty of comments inside the file so you will mostly figure out everything easily. A stripped version of my mailer.conf looks as following:

[general]
mail_command = /usr/sbin/sendmail
smtp_hostname = localhost

[defaults]
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
commit_subject_prefix = [SVN-Commit]
propchange_subject_prefix =
lock_subject_prefix =
unlock_subject_prefix =
from_addr = admin@mydomain.com
to_addr = receiver1@mydomain.com receiver2@mydomain.com
reply_to =
generate_diffs = add copy modify
commit_url = https://trac.mydomain.com/changeset/%(rev)s
show_nonmatching_paths = yes

[maps]

When the configuration file is in place, the next thing needs to be done is enable the actual hook. You will find several script template inside the hooks folder of your svn repo. Rename the one called post-commit.tmpl to post-commit and make it executable. The content of it is very simple, just replace the last line with

/usr/share/subversion/hook-scripts/mailer/mailer.py commit "$REPOS" "$REV"

That’s it. Next time when some one commits some code, the post-commit hook will trigger the mailer.py script and all the addresses in the to_addr field of the configuration file will receive an notification email.

0 comments:

Post a Comment