Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

login to bugzilla from a perl script

556 views
Skip to first unread message

Hicham Mouline

unread,
Apr 28, 2010, 6:21:45 PM4/28/10
to
Hello,

in a perl script, running:

use Bugzilla::Bug;
my $bug_instance = new Bugzilla::Bug(6);
$bug_instance->add_comment( "test comment" );
$bug_instance->update();

I need to login before running update. How do I login?

Does this use the WebService or is it something else?
There is another add_comment from WebService.

Regards,


Max Kanat-Alexander

unread,
Apr 28, 2010, 8:10:02 PM4/28/10
to support-...@lists.mozilla.org
On 04/28/2010 03:21 PM, Hicham Mouline wrote:
> use Bugzilla::Bug;
> my $bug_instance = new Bugzilla::Bug(6);
> $bug_instance->add_comment( "test comment" );
> $bug_instance->update();
>
> I need to login before running update. How do I login?

See how and where Bugzilla->login is called in .cgi scripts.

> There is another add_comment from WebService.

Yes, if you are using the WebService (which is the best way to
integrate with Bugzilla), you should just use the WebService methods.

-Max
--
http://www.everythingsolved.com/
Competent, Friendly Bugzilla and Perl Services. Everything Else, too.

Hicham Mouline

unread,
Apr 29, 2010, 5:01:36 AM4/29/10
to
"Max Kanat-Alexander" <mka...@bugzilla.org> wrote in message
news:mailman.2345.127249981...@lists.mozilla.org...

> On 04/28/2010 03:21 PM, Hicham Mouline wrote:
>> use Bugzilla::Bug;
>> my $bug_instance = new Bugzilla::Bug(6);
>> $bug_instance->add_comment( "test comment" );
>> $bug_instance->update();
>>
>> I need to login before running update. How do I login?
>
> See how and where Bugzilla->login is called in .cgi scripts.
>
>> There is another add_comment from WebService.
>
> Yes, if you are using the WebService (which is the best way to integrate
> with Bugzilla), you should just use the WebService methods.
This would then become:

Bugzilla::WebService::User::login( { login => "....", password => " ...
" } );
Bugzilla::WebService::Bug::add_comment( id => 6, comment => "test
comment" );
Bugzilla::WebService::User::logout();

right?

> -Max


Hicham Mouline

unread,
Apr 29, 2010, 5:53:44 AM4/29/10
to

"Hicham Mouline" <hic...@mouline.org> wrote in message
news:0PqdnfKvA-tt10TW...@mozilla.org...

> "Max Kanat-Alexander" <mka...@bugzilla.org> wrote in message
> news:mailman.2345.127249981...@lists.mozilla.org...
>> On 04/28/2010 03:21 PM, Hicham Mouline wrote:
>
> Bugzilla::WebService::User::login( { login => "....", password => " ...
> " } );

This appears to fail with this error:

"The function requires a login argument, and that argument was not set"

Any ideas?

Regards,


Max Kanat-Alexander

unread,
Apr 30, 2010, 3:22:36 PM4/30/10
to support-...@lists.mozilla.org
On 04/29/2010 02:01 AM, Hicham Mouline wrote:
>> This would then become:
>
> Bugzilla::WebService::User::login( { login => "....", password => " ...
> " } );
> Bugzilla::WebService::Bug::add_comment( id => 6, comment => "test
> comment" );
> Bugzilla::WebService::User::logout();
>
> right?

No, WebServices are designed to be accessed on a remote system via
XML-RPC or JSON-RPC, which are WebService protocols.

Hicham Mouline

unread,
Apr 30, 2010, 6:03:05 PM4/30/10
to

"Max Kanat-Alexander" <mka...@bugzilla.org> wrote in message
news:mailman.2508.127265536...@lists.mozilla.org...

> On 04/29/2010 02:01 AM, Hicham Mouline wrote:
>>> This would then become:
>>
>> Bugzilla::WebService::User::login( { login => "....", password => " ...
>> " } );
>> Bugzilla::WebService::Bug::add_comment( id => 6, comment => "test
>> comment" );
>> Bugzilla::WebService::User::logout();
>>
>> right?
>
> No, WebServices are designed to be accessed on a remote system via XML-RPC
> or JSON-RPC, which are WebService protocols.
>
> -Max

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?

Best regards,


la...@lancetek.com

unread,
Apr 25, 2014, 2:56:23 AM4/25/14
to

> 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();
}
0 new messages