#!/usr/bin/perl # The contents of this file are subject to the Mozilla Public License # Version 1.1 (the "License"); you may not use this file except in # compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the # License for the specific language governing rights and limitations # under the License. # # The Original Code is svn_bz_append.pl # # The Initial Developer of the Original Code is Toby Thain. # Portions created by Toby Thain are # Copyright (C) Toby Thain . All Rights Reserved. # # Contributor(s): Toby Thain # Based in part on Sean M. Foy's mail.pl # (http://sean-janus.optionpc.com/me/software/bugtraq/) # # works with Bugzilla 2.18.x # may require modification for other versions use strict; use warnings; use Text::Wrap; my $SVNLOOK = "/usr/bin/svnlook"; BEGIN { chdir "/var/www/localhost/htdocs/bugzilla-2.18.4"; push @INC, "contrib"; push @INC, "."; } require "globals.pl"; use BugzillaEmail; use Bugzilla::Config qw(:DEFAULT $datadir); use Bugzilla::BugMail; print STDERR "-"x10," commit hook\n"; die "usage: ",__FILE__," REPO_PATH REVISION" unless $#ARGV > 0; my $repo = $ARGV[0]; my $rev = $ARGV[1]; my $author; print STDERR "repo: $repo\n"; my $result = open(SVNAUTHOR,"$SVNLOOK author $repo -r $rev|") or die 'Couldn\'t exec svnlook author' ; chop($author = ); close SVNAUTHOR; # Find Bugzilla login from Svn committer user name. # You will probably need to customise this for your site. # this implementation assumes that Svn users are named fsmith # (initial+surname) and Bugzilla users are of the form fred.smith@some.domain SendSQL("SELECT login_name FROM profiles \ WHERE locate(\'.\',login_name) login_name $login_name\n"; my $message = "$repo rev $rev committed by $author\n"; print STDERR $message; # for docs about bugtraq properties, see # http://svn.collab.net/viewcvs/tortoisesvn/trunk/doc/issuetrackers.txt # whatever the user enters for %BUGID% my $bugpat = '(bug|issue)s?\s+([\d\s,#]+)'; # # Get bug number # my @bugs; $result = open(SVNLOG,"$SVNLOOK log $repo -r $rev|") or die 'Couldn\'t exec svnlook log' ; while () { $message .= $_; print STDERR "log: $_\n"; # extract bug list, if present m/$bugpat/i && do { @bugs = $2 =~ /\d+/g }; print STDERR "saw bugs: @bugs\n"; } close SVNLOG; if ( ! @bugs ){ print STDERR "No bug references found.\n"; exit 0; } # # Build Bugzilla comment # $message .= "\n"; $result = open(SVNFILES,"$SVNLOOK changed $repo -r $rev|") or die 'Couldn\'t exec svnlook changed' ; while () { $message .= $_; } close SVNFILES; $Text::Wrap::columns = 80; $message = wrap("", "", $message); foreach my $bug (@bugs) { AppendComment($bug,$login_name,$message); }