#!/usr/bin/perl # send a mail to svncommitters@HOSTNAME after every commit to a subversion # repository # # usage: # 1. save this script as /usr/local/libexec/svnmail.pl # 2. svnadmin create # 3. sudo ln -s /usr/local/libexec/svnmail.pl "/hooks/post-commit" # # modules use strict; use warnings; use Sys::Hostname; # constants my $SVNLOOK = "/usr/local/bin/svnlook"; my $SENDMAIL = "/usr/sbin/sendmail"; my @RECIPIENTS = qw(svncommitters); # command line parameters my $Repository = shift; my $Revision = shift; # check cmd line parameters die "usage: $0 " unless $Revision; # get info about svn revision my %Data = (); foreach (qw(author date log)) { $Data{$_}->{plain} = `'$SVNLOOK' '$_' '$Repository' -r '$Revision'`; $Data{$_}->{plain} =~ s/\r$|\n$//go; $Data{$_}->{html} = $Data{$_}->{plain}; $Data{$_}->{html} =~ s/\&/\&/go; $Data{$_}->{html} =~ s/\{html} =~ s/\>/\>/go; $Data{$_}->{html} =~ s/\"/\"/go; $Data{$_}->{html} =~ s/\'/\'/go; } foreach (qw(changed diff)) { $Data{$_}->{plain} = `'$SVNLOOK' '$_' '$Repository' -r '$Revision'`; $Data{$_}->{plain} =~ s/\r$|\n$//go; $Data{$_}->{html} = $Data{$_}->{plain}; $Data{$_}->{html} =~ s/\))[0]."\@$Hostname"; my $To = join(", ", map { "$_\@$Hostname" } @RECIPIENTS); # send mail open(PH, "|$SENDMAIL -t") or die "$SENDMAIL: $!"; print PH <{plain}) Content-Type: text/html; charset=utf-8

Subversion commit report

EOF close(PH) or die "$SENDMAIL: $!";
Repository:$Repository
Revision:$Revision
Author:$Data{author}->{html}
Date:$Data{date}->{html}
Log:$Data{log}->{html}
Changed files:
$Data{changed}->{html}
Differences:
$Data{diff}->{html}