How to use bugzilla API in existing bugzilla code?

喜欢而已 提交于 2019-12-24 12:14:25

问题


Well, at the moment i have two goals.

  1. User don't have Edit bug rights in bugzilla, but he/she should write/post comments on that bug. I think this could be possible by the following API, but I am not sure, since I am new in bugzilla and Perl. http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#add_comment

  1. I want to import bugs by using importxml.pl, but I don't want new entries in DB. I just want to modify some fields of existing bugs of bugzilla, on the base of bug.xml file which contains bug info.

    i.e. perl -T C:\bugzilla\bugzilla\importxml.pl -v C:\bugzilla\bugzilla\mybugs\bug.xml

Might be following API could be helpful, but I am not sure.

http://www.bugzilla.org/docs/tip/en/html/api/Bugzilla/WebService/Bug.html#update


So, what are possible ways to achieve these goals ??

As I am thinking, may be i should use the methods of these APIs into existing bugzilla code and my dreams are:

  1. comments would be enabled for the user who don't have bug-edit right.
  2. I'll run the importxml.pl script from command line by passing some parameters and I'll modify some fields of existing bugs.

But I am not sure, either I am thinking right or wrong. I also don't know how to use the method of these APIs??


回答1:


The email_in.pl script can do the types of things you are asking. However, you will need to create a user that does have permissions to make the changes and you will need to transform the data into a form that email_in.pl understands.

http://www.bugzilla.org/docs/4.2/en/html/api/email_in.html




回答2:


I can help with the first point:

Here's an excerpt from a a svn_bz_append.pl script (http://www.telegraphics.com.au/svn/svn_bz/trunk/) that I've modified that I use to update bugzilla comments on svn commits. Note that I have this script running on the same machine as the Bugzilla install, as it uses modules from within the Bugzilla directory. I have this working for Bugzilla v 4.2.3.

I've omitted quite a bit of this script to pull out the excerpt below:

use strict;
use warnings;

use Bugzilla;
use Bugzilla::Config;
use Bugzilla::Bug;

use Data::Dumper;

... create/fetch the userid and some bug Ids to work on ...

eg:

my $userid = 1;
my @bugs = ( 1, 2, 3 );
my $message = 'Say something here';

... now loop through the bug ids and add the comment...

foreach my $bugId (@bugs) {

my $user = new Bugzilla::User({ id => $userid}) 
 || ThrowUserError('invalid_username', { id => $userid}); #get the user from bugzilla
print STDERR 'user: '. Dumper($user); #pretty prints the user object

Bugzilla->set_user($user); #this authenticates the user so that you may perform actions on bugs that the user has permissions to.

my $bug = Bugzilla::Bug->check($bugId); #gets the bug
print STDERR 'bug: '. Dumper($bug); #pretty prints the bug object

$bug->add_comment($message); #adds a comment to the bug
$bug->update(); #updated the bug - don't forget to do this!

}

Please note that the Dumper functions are just using the excellent Data::Dumper module: http://perldoc.perl.org/Data/Dumper.html - you don't need them except for debugging.

The log in info came from: How can I authenticate when using the Bugzilla Perl API in a script?



来源:https://stackoverflow.com/questions/10336884/how-to-use-bugzilla-api-in-existing-bugzilla-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!