Recently I needed to extend svn functionality by adding post commit email notifications for small open source project. The idea was to have some possibility to make commit visible for team members without annoying manual emailing (like “please see commit #123 – I added fluent nhibernate configuration”). We wanted to save our time and have some kind of switch for indicating that this commit is public. Another requirement is that we didn’t want all commits public – we wanted to notify only about those commits which were useful for other team members (of course author of commit decided is it useful or not for other :) ).
In order to implement described behavior I needed to make several things:
- Add post commit hook in svn server which sends email notifications
- Make it possible to send notifications by some condition. We decided to use ‘!’ symbol as indicator that commit is public. I.e. if contributor adds ‘!’ as first symbols in commit description, then notification should be sent (like “!Fluent nhibernate configuration added")
In order to achieve 1st step I decided to use standard mailer.py script which comes from subversion-tools. There were some drawbacks with installing it on windows. So I will describe the process step by step:
- Install python 2.6.x on svn server. On the moment when this post is written it is 2.6.4. Note that currently I didn’t not use 3.x version as I didn’t find python bindings for svn for 3.x versions (see below)
- Install python bindings from subversion site . On the moment of installing python bindings I had svn 1.6.6 but binsings was only for 1.6.2. Nevertheless it worked on 1.6.6.
- Copy mailer.py and mailer.conf into svn server (I copied it into …\repository\hooks\hook-scripts folder). mailer.conf file can be found on the same page with subversion-tools.
- Edit mailer.conf. There are many comments in this file which describe mailer configuration. I needed simple solution with sending mails via smtp. So this is stripped configuration file I used:
- Create post-commit.cmd script in …\repository\hooks folder:
Note that it is important to have “generate_diffs = none”. Without it you will need to configure diff tool (via “diff” option)
Note that absolute path is used here
After that recipients (specified in “to_addr” option in mailer.conf) will receive notifications after each commit.
Second step is to make these notifications conditional. It will require slightly change of mailer.py script:
After that notifications are sent only if contributor typed ‘!’ symbol in commit description.