I was searching for a little script able to email my collaborators and myself when someone commits something to my SVN repositories.

SVN commit email - sample email

There seem to be a popular perl script commit-email.pl. But I had several errors when implementing it. This is why I decided to make one. Because it's useful and easy to configure, I'll share my entire script here.

Download commit-email.php

As you can see, there is a little configuration section.

  1. <?php
  2.  
  3. // CONFIGURATION
  4. $svnlook = '/usr/bin/svnlook';
  5. $globaladdress = 'someone+logs@gmail.com';
  6. $repoaddress = array(
  7. 'repoAAA' => 'user1@aaa.com, user2@aaa.com',
  8. 'repoBBB' => 'user1@b.com, user2@b.com',
  9. );
  10. $from = 'svn-noreply@svn-hosting.lol';
  11. $replyto = 'admin@svn-hosting.lol';
  12. //

Nothing fancy here. $svnlook is the path where the svnlook command can be run. $globaladdress is a email address where all commit will be notified. $repoaddress is a field for specific repositories to add email addresses. $from and $replyto are what they are.

It's following the svn postcommit hook. My SVN repos are located in /home/svn. You can create a hook in /home/svn/repoX/hooks/post-commit containing:

  1. #!/bin/sh
  2.  
  3. REPOS="$1"
  4. REV="$2"
  5.  
  6. /usr/bin/php /home/svn/commit-email.php "$REPOS"

Don't forget to place my script in /home/svn and to install php5-cli.