#!/usr/bin/perl # Subversion commit hook to write detailed summary to a FIFO # Copyright (C) 2006-7 Toby Thain # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # you may need a full path here: my $SVNLOOK = "svnlook"; # this must be the FIFO used in your fifobot.pl script: open(FIFO,">/tmp/svnbot") or die "can't open FIFO"; # get parameters my($REPO,$REV) = @ARGV; my $A = `$SVNLOOK author $REPO -r $REV`; chomp($A); my $L = `$SVNLOOK log $REPO -r $REV`; chomp($L); my $PROJ = `basename $REPO`; chomp($PROJ); my $LABEL = " $PROJ | r$REV | $A "; my $SPACE = "|".(" " x length($LABEL)); print FIFO "|$LABEL| $L\n"; my $showlines = 5; # maximum number of changed items to show my $n = 0; my $skipped = 0; my %counts; my $lastline; # fetch names of changed items open(CHANGED,"$SVNLOOK changed $REPO -r $REV|"); while(){ $lastline = "$SPACE| $_"; if($n < $showlines){ print FIFO $lastline; } else{ # skip it, but update appropriate count (add, delete or update) ++$counts->{substr($_,0,1)}; ++$skipped; } ++$n; } close(CHANGED); if($skipped == 1){ print FIFO $lastline; }elsif($skipped > 1){ my $msg; # print summary of skipped items if($counts->{'A'}){ $msg .= " $counts->{'A'} added"; } if($counts->{'D'}){ $msg .= " $counts->{'D'} deleted"; } if($counts->{'U'}){ $msg .= " $counts->{'U'} updated"; } if($msg){ print FIFO "$SPACE| ...and another$msg\n"; } } # link to WebSVN or Trac revision page (N.B. SITE DEPENDENT! # you will want to change or disable this, then uncomment) #print FIFO "$SPACE| See: http://SERVER/websvn/listing.php?repname=$PROJ&rev=$REV\n"; #print FIFO "$SPACE| See: http://SERVER/trac/$PROJ/changeset/$REV\n"; # link to Bugzilla or Trac issues mentioned in commit message. # (N.B. SITE DEPENDENT! - customise, then uncomment lines below) # you may also want this script: http://telegraphics.com.au/svn/svn_bz/trunk/ my $bugpat = '(bug|issue)s?:?([\d\s,#and&]+)'; # Trac users might want: '(ticket:|#)(\d+)' while($L =~ /$bugpat/gsi){ $_ = $2; while(m/(\d+)/g){ # print FIFO "$SPACE| Bug $1: http://SERVER/bugzilla/show_bug.cgi?id=$1\n"; # print FIFO "$SPACE| Ticket $1: http://SERVER/trac/$PROJ/ticket/$1\n"; } } close(FIFO);