> So then, if the perl script runs in the same box as the httpd/bugzilla,
> which feature should I use?
> This is basically the source release management server (subversion) which
> run the perl script as a post commit hook
>
> How should this local perl script login to Bugzilla in order to add comments
> to a bug?
I've done this same thing using this script as a basis:
http://www.telegraphics.com.au/svn/svn_bz/trunk/
These two Stack Overflow answers were helpful:
see:
http://stackoverflow.com/questions/2769469/how-can-i-authenticate-when-using-the-bugzilla-perl-api-in-a-script
see:
http://stackoverflow.com/questions/10336884/how-to-use-bugzilla-api-in-existing-bugzilla-code/23286110#23286110
Here's the script in case anyone is interested. I've modified it for Visual Svn Server and bugzilla 4.2.3:
#!/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 <toby at
telegraphics.com.au>. All Rights Reserved.
#
# Contributor(s): Toby Thain, Matthew Curry
# Portions created by Matthew Curry are
# Copyright (C) Matthew Curry <mcurry at
skarven.net>. 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 = '"C:\\Program Files (x86)\\VisualSVN Server\\bin\\svnlook.exe"';
BEGIN {
chdir 'D:\\inetpub\\wwwroot\\bugzilla-4.2.3';
push @INC, "contrib";
push @INC, ".";
}
use Bugzilla;
use Bugzilla::Config;
use Bugzilla::Bug;
use Data::Dumper;
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\@
domain.com\';");
# this version assumes that Svn users are named fsmith (initial+surname)
# and Bugzilla users are of the form fred....@some.domain
# my @rec = Bugzilla->dbh->selectrow_array("SELECT login_name,userid FROM profiles \
# WHERE locate(\'.\',login_name)<locate(\'@\',login_name) \
# and lower(concat(left(login_name,1),substring(login_name,locate(\'.\',login_name)+1, \
# locate(\'@\',login_name)-locate(\'.\',login_name)-1))) = \'$author\';");
my $login_name = shift @rec;
my $userid = shift @rec;
die("Bugzilla login_name not found for $author\n") unless defined($login_name) and defined($userid);
print STDERR "author $author -> 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`;
print STDERR "log: $log\n";
$message .= $log;
my $viewvcurl = "\nhttp://
someserver.example.com/viewsrc/svn?view=rev&revision=$rev \n";
$message .= $viewvcurl;
print STDERR "viewvcurl: $viewvcurl\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: $message\n";
# AppendComment($bugid, $whoid, $comment, $isprivate, $timestamp, $work_time)
##foreach my $bug (@bugs) {AppendComment($bug,$userid,$message)}
foreach my $bugId (@bugs) {
#my $user = Bugzilla::User->check({ id => $userid});
my $user = new Bugzilla::User({ id => $userid})
|| ThrowUserError('invalid_username', { id => $userid});
print STDERR 'user: '. Dumper($user);
Bugzilla->set_user($user);
#my $user = Bugzilla->login();
my $bug = Bugzilla::Bug->check($bugId);
print STDERR 'bug: '. Dumper($bug);
$bug->add_comment($message);
$bug->update();
}