Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /data/sites/web/remonpelnl/www/wp-content/plugins/rmp_bitly/rmp_bitly.php on line 20
Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /data/sites/web/remonpelnl/www/wp-content/plugins/rmp_bitly/rmp_bitly.php on line 20
Deprecated: pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated in /data/sites/web/remonpelnl/www/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 84
When you work with a group of people on the same projects, the larger the group gets, the more difficult the task of keeping everybody informed. So why not do this automatically? Send an e-mail upon an SVN commit. Here’s how I do it.
First, we need a script to send the actual message. Now please keep in mind that I do all this on an OSX machine and Apple sometimes tinkers with available parameters to certain commands.
Also note that I am running my SVN server as Apache Module and following instruction apply to that situation.
In this script the command
1 |
mail |
is used and Apple’s implementation lacks the -a parameter. Here’s the script;
#!/bin/bash
REPOPATH=$1
REV=$2
SENDTO=send-to-me@mail.tld
SENDFROM=send-as-this@mail.tld
REPLYTO=replies-go-here@mail.tld
LIMITDIFF=200
CHANGELOG=`svnlook log -r $REV $REPOPATH`
AUTHOR=`svnlook author -r $REV $REPOPATH`
CHANGED=`svnlook changed -r $REV $REPOPATH`
DIFF=`svnlook diff -r $REV $REPOPATH | head -n $LIMITDIFF`
DATE=`date`
TMPFILE=/tmp/svn$REV-$RANDOM.message
SUBJECT="SVNCommit ($AUTHOR) $REPOPATH [$REV]"
echo "-------------------- SVN Commit Notification --------------------
Repository: $REPOPATH
Revision: $REV
Author: $AUTHOR
Date: $DATE
-----------------------------------------------------------------
Log Message:
-----------------------------------------------------------------
$CHANGELOG
-----------------------------------------------------------------
Changes:
-----------------------------------------------------------------
$CHANGED
-----------------------------------------------------------------
Diff: (only first $LIMITDIFF lines shown)
-----------------------------------------------------------------
$DIFF
" > $TMPFILE
# Send email
# use hack as shown here: http://stackoverflow.com/a/11656356
# apple's mail command does not allow extra headers with -a, so we insert the headers into the subject
/usr/bin/mail -s "$(echo -e "$SUBJECT\nFrom: $SENDFROM\nReply-to: $REPLYTO\n")" "$SENDTO" < $TMPFILE
# Cleanup
rm $TMPFILE
Now, this script must be executable by the webserver., so this file should either be 750 or 755, depending on your apache configuration. In my case, Apache runs as _www:wheel, and my group is wheel as well, so 750 will do.
Second part is informing SVN to use this script.
This is a bit tricky, but with some investigation, it’s not hard.
We’ll need to know the subversion repository path. If you set it up yourself, you will know, in my case, I have one SVN repo at /Volumes/SVN/myrepository. This folder contains SVN files and folders, and one of those is hooks. If you take a look in this folder, you’ll see template files, like post-commit.tmpl. If you don’t, you’re in the wrong place!
Create a file there called post-commit (same as the template, but no extention) with the following contents:
Be sure this file is owned by the same user and group the repository is owned by, in my case _www:wheel. If you had to use sudo to create the file this is very important. Also give this file 750 or 755 depending on your configuration.
Third – and last – restart Apache.
sudo apachectl restart
Please note:
You will have to replace some values and paths in both scripts.
Also note the use of a hack in the first script; as MoSs explains on StackOverflow. Thank you!
Next thing is to install the code base on a testing location and only allow the commit if certain selenium test cases succeed! :-)
Great idea. Also been thinking of using the signal to figure out which project is changed and checking to see what developers worked on it and send those users a mail, instead of a fixed list.