SVN post-commit hook E-mail report; sends diff as attachment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
FROMADDRESS="svn@`hostname --fqdn`" | |
USAGE="Usage: `basename $0` -d PATH -mailto MAILTO\n\nCreates a commit report and sends it via E-mail\n\nValid options:\n\n\t-d PATH : specify repository path PATH (required)\n\t-mailto MAILTO : specify report recipients MAILTO,\n\t comma-separated (required)\n\t-rev ARG : specify repository revision ARG, defaults to\n\t youngest revision\n\t-name ARG : specify repository nice name ARG, defaults to\n\t basename of PATH\n\n" | |
if [ $# -eq 0 ] | |
then | |
echo -e >&2 "$USAGE"; exit 3; | |
fi | |
REPO="" | |
MAILTO="" | |
REV="" | |
NAME="" | |
while [ $# -gt 0 ] | |
do | |
case "$1" in | |
-d) REPO="$2"; shift;; | |
-mailto) MAILTO="$2"; shift;; | |
-rev) REV="$2"; shift;; | |
-name) NAME="$2"; shift;; | |
*) echo -e >&2 "$USAGE"; exit 3;; | |
esac | |
if [ $# -eq 0 ] | |
then | |
echo >&2 "`basename $0`: missing argument"; exit 3; | |
fi | |
shift | |
done | |
if [ -z $REPO ] | |
then | |
echo >&2 "`basename $0`: missing required option -d"; exit 3; | |
fi | |
if [ -z $MAILTO ] | |
then | |
echo >&2 "`basename $0`: missing required option -mailto"; exit 3; | |
fi | |
if [ -z $REV ] | |
then | |
REV=`svnlook youngest $REPO` | |
fi | |
FILENAME=`basename $REPO` | |
if [ -z $NAME ] | |
then | |
NAME="SVN: $FILENAME" | |
fi | |
LOG=`svnlook log $REPO -r $REV` | |
LOG1=`svnlook log $REPO -r $REV | head -n1` | |
CHANGED=`svnlook changed $REPO -r $REV` | |
AUTHOR=`svnlook author $REPO -r $REV` | |
REVDATE=`svnlook date $REPO -r $REV` | |
BOUNDARY=_`date | md5sum | cut -d\ -f1`_ | |
/usr/sbin/sendmail -f $FROMADDRESS $MAILTO <<EOF | |
Content-Type: multipart/mixed; | |
boundary="_001$BOUNDARY" | |
From: $FROMADDRESS | |
To: $MAILTO | |
Subject: [$NAME][$REV] $LOG1 | |
Date: `date -R` | |
MIME-Version: 1.0 | |
--_001$BOUNDARY | |
Content-Type: multipart/alternative; | |
boundary="_002$BOUNDARY" | |
--_002$BOUNDARY | |
Content-Type: text/plain | |
Revision | |
$REV | |
Author | |
$AUTHOR | |
Commit Date | |
$REVDATE | |
== Log Message == | |
$LOG | |
== Changes == | |
$CHANGED | |
--_002$BOUNDARY | |
Content-Type: text/html | |
<dl> | |
<dt>Revision</dt><dd>$REV</dd> | |
<dt>Author</dt><dd>$AUTHOR</dd> | |
<dt>Commit Date</dt><dd>$REVDATE</dd> | |
</dl> | |
<h3>Log Message</h3><pre>$LOG</pre> | |
<h3>Changes</h3><pre>$CHANGED</pre> | |
--_002$BOUNDARY-- | |
--_001$BOUNDARY | |
Content-Type: application/octet-stream | |
Content-Transfer-Encoding: base64 | |
Content-Disposition: attachment; filename="$FILENAME-$REV.diff.gz" | |
`svnlook diff $REPO -r $REV | gzip | base64` | |
--_001$BOUNDARY-- | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
/path/to/commit-report.sh -d "$1" -mailto "foo@foo.local,bar@foo.local" -rev "$2" |
Thanks! Minor tweaks I had to make to have the script work under FreeBSD:
-#!/bin/bash
+#!/usr/local/bin/bash
-FROMADDRESS="svn@`hostname --fqdn`"
+FROMADDRESS="svn@`hostname -f`"
-BOUNDARY=_`date | md5sum | cut -d\ -f1`_
+BOUNDARY=_`date | md5 | cut -d\ -f1`_
-Date: `date -R`
+Date: `date "+%a, %d %b %Y %T %z (%Z)"`
-`svnlook diff $REPO -r $REV | gzip | base64`
+`svnlook diff $REPO -r $REV | gzip | openssl enc -base64`
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://ten-fingers-and-a-brain.com/2012/01/subversion-post-commit-hook-e-mail-report-script-that-sends-the-diff-as-an-attachment/ for more details