#!/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, Matthew Curry # Portions created by Matthew Curry are # Copyright (C) Matthew Curry . All Rights Reserved. # # Based in part on Sean M. Foy's mail.pl # (http://sean-janus.optionpc.com/me/software/bugtraq/) # works with Bugzilla 3.2rc1; may require modification for other versions # for Bugzilla 2.x, see http://www.telegraphics.com.au/svn/svn_bz/tags/ use strict; use warnings; #use Text::Wrap; #Put your path to svnlook here and do not forget "exe" on windows platform my $SVNLOOK = "\"C:\\Program Files\\VisualSVN Server\\bin\\svnlook.exe\""; #Set it to your location of Bugzilla BEGIN { chdir "C:\\BugZilla"; push @INC, "contrib"; push @INC, "."; } use Bugzilla; use Bugzilla::Config; use Bugzilla::Bug; print STDERR "-"x10," commit hook\n"; die "usage: ",__FILE__," REPO_PATH REVISION" unless $#ARGV > 0; my ($repo,$rev) = @ARGV; print STDERR "repo: $repo\n"; print STDERR "rev: $rev\n"; chop(my $author = `$SVNLOOK author $repo -r $rev`); # Find Bugzilla login from Svn committer user name. # You will probably need to customise this for your site. my @rec = Bugzilla->dbh->selectrow_array("SELECT login_name,userid FROM profiles \ WHERE lower( substring( login_name, 1, locate( \'@\', login_name ) -1 ) ) = \'$author\';"); # this version assumes that Svn users are named fsmith (initial+surname) # and Bugzilla users are of the form fred.smith@some.domain # my @rec = Bugzilla->dbh->selectrow_array("SELECT login_name,userid FROM profiles \ # WHERE locate(\'.\',login_name) login_name '$login_name', userid '$userid'\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(s) my @bugs; my $log = `$SVNLOOK log $repo -r $rev`; $message .= $log; #Set this variable to proper ViewVC URL (http://viewvc.tigris.org) my $viewvcurl = "\nhttp://YourServer.com/viewvc/viewvc.cgi?view=rev&revision=$rev Revision overview.\n"; $message .= $viewvcurl; print STDERR "log: $log\n"; # extract bug list, if present while($log =~ /$bugpat/gsi){ @bugs = (@bugs,$2 =~ /\d+/g) } warn "No bug references found" unless @bugs; print STDERR "saw bugs: @bugs\n"; # add committed file list $message .= "\n" . `$SVNLOOK changed $repo -r $rev`; # longdescs are stored unwrapped in Bugzilla 2.20+ #$Text::Wrap::columns = 80; #$message = wrap("", "", $message); print STDERR $message; #Add bug comment to Bugzilla. foreach my $xxxbug (@bugs) { my $myuser = new Bugzilla::User({ name => $login_name}); Bugzilla->set_user($myuser); my $mybug = new Bugzilla::Bug($xxxbug); $mybug->add_comment($message); $mybug->update; }