Howto: Connect TWiki to Bugzilla API

Preparation

Following perl moduls are needed to use the bugzilla API:

Install them from cpan.org.

Also bz_webservice_demo.pl is needed, get the file from the bugzilla package (download bugzilla-3.?.?.tar.gz from: bugzilla.org, file in folder: bugzilla-3.0.4/contrib)

First steps

At first, we will check if a basic connect to the bugzilla api is possible:

 # perl bz_webservice_demo.pl --uri http://connection.to/bugzilla/xmlrpc.cgi --login username --password mypassword 

Should return:

 Connecting to a Bugzilla of version 3.?.?. Bugzilla's timezone is ????. Login successful. 

If not, check if url is not correct, or if there is a firewall who blocks ...

Create a new bug entry

Basic code

 use File::Basename qw(dirname); use File::Spec; use HTTP::Cookies; use XMLRPC::Lite; ... my %bug_values = ( product => 'ExampleProd', component => 'Prod8', summary => 'API Test', version => '1.0', description => 'This is a description', op_sys => 'All', platform => 'All', severity => 'normal', priority => 'P5' ); # all these field are required $soapresult = $proxy->call('Bug.create', \%bug_values); _die_on_fault($soapresult); $result = $soapresult->result; if (ref($result) eq 'HASH') { foreach (keys(%$result)) { print "$_: $$result{$_}\n"; } } else { print "$result\n"; } 

Use TWiki for bug creation

Please note, code has written very rough and isn't a very good example for a twiki extension, but it will show you how TWiki and Bugzilla API work together and that's a beginning.

Frontend

At first we start with the twiki site (all files are uploaded, see attachment):

bugapi_frontend.png

TWiki bin/publishbug

The connector between form and plugin (see bin/view for more informations)

 ... use TWiki::Plugins; use TWiki::Plugins::BugzillaAPIPlugin; TWiki::UI::run( \&TWiki::Plugins::BugzillaAPIPlugin::createBug ); 

TWiki lib/TWiki/Plugins/BugzillaAPIPlugin.pm

The main code, there are code comments in BugzillaAPIPlugin.pm which might help you.

 ... # connection to bugzilla api my $Bugzilla_uri = "http://myaddress.to/bugzilla/xmlrpc.cgi"; my $cookie_jar = new HTTP::Cookies('file' => File::Spec->catdir(dirname($0), 'cookies.txt'), 'autosave' => 1); my $proxy = XMLRPC::Lite->proxy($Bugzilla_uri, 'cookie_jar' => $cookie_jar); # try to login to bugzilla my $bugzilla_user = "<user>\@<domain>"; my $bugzilla_pwd = "<pwd>"; # Log in. my $soapresult = $proxy->call('User.login', { login => $bugzilla_user, password => $bugzilla_pwd, remember => 0 } ); # If login failed if ($soapresult->fault) { my ($package, $filename, $line) = caller; &TWiki::Func::writeDebug( "BugzillaAPIPlugin::createBug: Login failed: " . $soapresult->faultcode . " " . $soapresult->faultstring ) if $localdebug; throw TWiki::OopsException( 'attention', def=>'SOAP_error', web => $session->{webName}, topic => $session->{topicName}, params => [ $soapresult->faultcode . ' ' . $soapresult->faultstring . " in SOAP call near $filename line $line.\n" ] ); return; } &TWiki::Func::writeDebug( "BugzillaAPIPlugin::createBug: Login successful" ) if $localdebug; # let's create a bug $soapresult = $proxy->call('Bug.create', \%createInfo); # if creation failed: if ($soapresult->fault) { my ($package, $filename, $line) = caller; &TWiki::Func::writeDebug( "BugzillaAPIPlugin::createBug: Create Bug failed: " . $soapresult->faultcode . " " . $soapresult->faultstring ) if $localdebug; throw TWiki::OopsException( 'attention', def=>'SOAP_error', web => $session->{webName}, topic => $session->{topicName}, params => [ $soapresult->faultcode . ' ' . $soapresult->faultstring . " in SOAP call near $filename line $line.\n" ] ); return; } my $result = $soapresult->result; my $bugid; if (ref($result) eq 'HASH') { foreach (keys(%$result)) { &TWiki::Func::writeDebug( "BugzillaAPIPlugin::createBug: $_: $$result{$_}\n") if $localdebug; $bugid = $$result{$_}; } } else { &TWiki::Func::writeDebug("BugzillaAPIPlugin::createBug: unexpected result\n") if $localdebug; } 

Add comment

under construction

-- Contributors: SaschaVetter - 08 Aug 2008

Discussion

Topic attachments
I Attachment History Action Size Date Who Comment
Perl source code filepm BugzillaAPIPlugin.pm r1 manage 5.9 K 2008-08-08 - 12:57 UnknownUser Plugin code
Texttxt CreateNewBugForm.txt r1 manage 11.5 K 2008-08-08 - 12:58 UnknownUser TWiki Frontend - Code
PNGpng bugapi_frontend.png r1 manage 6.4 K 2008-08-08 - 12:56 UnknownUser TWiki Frontend
Unknown file formatext publishbug r1 manage 1.1 K 2008-08-08 - 12:56 UnknownUser  
Edit | Attach | Watch | Print version | History: r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r2 - 2008-08-08 - SaschaVetter
 
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.