#!/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.0.4; 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; my $SVNLOOK = "/usr/bin/svnlook"; BEGIN { chdir "/var/www/html/bugzilla-3.0.4"; 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"; 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 login_name = \'$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; my $viewvcurl = "\nhttp://someserver.example.com/viewsrc/svn?view=rev&revision=$rev \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; my $user = new Bugzilla::User($userid); Bugzilla->set_user($user); foreach my $referenced_bug (@bugs) { my $bug_instance = new Bugzilla::Bug->check($referenced_bug); $bug_instance->add_comment( $message ); $bug_instance->update(); }