#!/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.20; may require modification for other versions # IMPORTANT: See README for information on a bug fix required in Bugzilla 2.20 # for Bugzilla 2.18.x, see http://www.telegraphics.com.au/svn/svn_bz/tags/release-2.18.x/ use strict; use warnings; #use Text::Wrap; my $SVNLOOK = "/usr/bin/svnlook"; BEGIN { chdir "/var/www/localhost/htdocs/bugzilla-2.20"; push @INC, "contrib"; push @INC, "."; } require "globals.pl"; use Bugzilla::Config qw(:DEFAULT $datadir); 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. # this implementation 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 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(s) my @bugs; my $log = `$SVNLOOK log $repo -r $rev`; $message .= $log; 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); # AppendComment($bugid, $whoid, $comment, $isprivate, $timestamp, $work_time) foreach my $bug (@bugs) { AppendComment($bug,DBNameToIdAndCheck($login_name),$message) }