Svn Notify

Have you ever needed to configure subversion in order to send mails containing details about the latest commit?
Well on the net you can find a lot of scripts useful for this purpose, but i decided to write my own one in order to make it as simple as possible!
External packages needed: nc (netcat).

#!/usr/bin/env bash

SERVER=smtp.tiscali.it
DOMAIN=tiscali.it

if [ $# -lt 3 ]; then
	printf "Usage: $0 path revision address1 address2 ..\n"
	exit 1
fi

REPO="$1"
PROJECT="`basename $REPO`"
FROM="notify-$PROJECT@mldb.net"
REVISION=$2
OLD=$(( $REVISION - 1 ))
shift
shift

MESSAGE="`mktemp`"

printf "HELO $DOMAIN\n" >> $MESSAGE
printf "MAIL FROM: <$FROM>\n" >> $MESSAGE
for i; do
	printf "RCPT TO: <$i>\n" >> $MESSAGE
done
printf "DATA\n" >> $MESSAGE
printf "From: MLDB Commit Notify <$FROM>\n" >> $MESSAGE
printf "To: " >> $MESSAGE
for i; do
	printf "<$i>," >> $MESSAGE
done
printf "\n" >> $MESSAGE
printf "Subject: $PROJECT: revision $REVISION\n" >> $MESSAGE
printf "\n" >> $MESSAGE

svn log file://"$REPO" -r $REVISION >> $MESSAGE
svn diff file://"$REPO" -r $OLD:$REVISION >> $MESSAGE

printf ".\n" >> $MESSAGE
printf "QUIT\n" >> $MESSAGE

nc $SERVER 25 < $MESSAGE

rm $MESSAGE

Tags: , , ,

Leave a Reply

You must be logged in to post a comment.