четверг, 9 сентября 2010 г.

HOWTO use Bugzilla WebService : User login and get bugs info

HOWTO use Bugzilla::WebService - The Web Service interface to Bugzilla.
User login and get bugs info.


#!/usr/bin/php

/*
  HOWTO use Bugzilla::WebService - The Web Service interface to Bugzilla
  User login and get bugs info.

  (c) 2010 Yuri Timofeev
  GPLv3

  See also http://www.bugzilla.org/docs/3.2/en/html/api/Bugzilla/WebService.html
 */

$URI = 'http://bugzilla.domain/xmlrpc.cgi';
$xml_data = array(
    'login' => 'email@email.com',
    'password' => 'password here',
    'remember' => 1
);
$bug_ids = array(5000, 5001);  // bugs list
$file_cookie = tempnam('', 'bugzilla-cookie');
$options = array(
//    CURLOPT_VERBOSE => true,
    CURLOPT_URL     => $URI,
    CURLOPT_POST    => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER  => array( 'Content-Type: text/xml', 'charset=utf-8' )
);



//------ Login and receive bugzillas cookies
$ch = curl_init();
curl_setopt_array($ch, $options);
$request = xmlrpc_encode_request("User.login", $xml_data); // see also  http://www.bugzilla.org/docs/3.2/en/html/api/Bugzilla/WebService/User.html
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEJAR, $file_cookie);
/* Returns: On success, a hash containing one item, id, the numeric id of the user that was logged in.
   A set of http cookies is also sent with the response.
   These cookies must be sent along with any future requests to the webservice, for the duration of the session. */
$server_output = curl_exec($ch); // Array( [id] => 1 ) for example

$response = xmlrpc_decode($server_output);
if (empty($response['id']))
    trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
curl_close($ch);



//------ Login (send cookies) and get bugs info
$ch = curl_init();
curl_setopt_array($ch, $options);
$xml_data['ids'] = $bug_ids;
$request = xmlrpc_encode_request("Bug.get", $xml_data); // see also  http://www.bugzilla.org/docs/3.2/en/html/api/Bugzilla/WebService/Bug.html
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_COOKIEFILE, $file_cookie);
$server_output = curl_exec($ch);
curl_close($ch);

$response = xmlrpc_decode($server_output);
if (xmlrpc_is_fault($response))
    trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
else
    print_r($response);

unlink($file_cookie);
?>


And return info about dependson и blocked (Bugzilla version 3.2)

diff -u Bugzilla/WebService/Bug.pm.original Bugzilla/WebService/Bug.pm
--- Bugzilla/WebService/Bug.pm.original 2010-09-09 14:19:34.000000000 +0300
+++ Bugzilla/WebService/Bug.pm  2010-09-09 14:43:45.000000000 +0300
@@ -96,6 +96,10 @@
         $item{'id'}               = type('int')->value($bug->bug_id);
         $item{'summary'}          = type('string')->value($bug->short_desc);
 
+        # tim4dev
+        $item{'dependson'}        = $bug->dependson;
+        $item{'blocked'}          = $bug->blocked;
+
         if (Bugzilla->params->{'usebugaliases'}) {
             $item{'alias'} = type('string')->value($bug->alias);
         }

0 коммент.:

Отправить комментарий