Use bugzilla advanced search results returned as CSV as a simple and efficient read-only API to query Bugzilla. The official bugzilla API doesn't allow searching all of the fields, the advanced query page does. In most of the cases, what you want are bug numbers and bug titles from a search query. Since we can now get bug numbers from an arbitra…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getBugsFromCSV($csv, $full = false) | |
{ | |
$shortBugs = $fullBugs = $temp = []; | |
if (($handle = fopen($csv, 'r')) !== false) { | |
while (($data = fgetcsv($handle, 300, ',')) !== false) { | |
if ($data[0] == 'bug_id') { | |
$fields = $data; | |
continue; | |
} | |
foreach ($fields as $key => $field) { | |
$temp[$field] = $data[$key]; | |
} | |
$fullBugs[] = $temp; | |
$shortBugs[$temp['bug_id']] = $temp['short_desc']; | |
} | |
fclose($handle); | |
} | |
return ($full) ? $fullBugs : $shortBugs; | |
} | |
function cacheUrl($url, $time = 60) | |
{ | |
$cache = __DIR__ . '/cache/' . sha1($url) . '.cache'; | |
if (is_file($cache)) { | |
$age = $_SERVER['REQUEST_TIME'] - filemtime($cache); | |
if ($age < $time) { | |
return $cache; | |
} | |
} | |
$file = file_get_contents($url); | |
file_put_contents($cache, $file); | |
return $cache; | |
} | |
$bugzillaQueryUrl = 'https://bugzilla.mozilla.org/buglist.cgi?'; | |
$request ='bug_status=UNCONFIRMED' | |
. '&bug_status=NEW' | |
. '&bug_status=ASSIGNED' | |
. '&bug_status=REOPENED' | |
. '&emailassigned_to1=1' | |
. '&email1=pascalc%40gmail.com'; | |
$request .= '&ctype=csv'; | |
$csv = $bugzillaQueryUrl . $request; | |
var_dump( | |
getBugsFromCSV( | |
cacheUrl($csv) | |
) | |
); | |
var_dump( | |
getBugsFromCSV( | |
cacheUrl($csv), | |
true | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This has changed recently in that you can now use the REST/XMLRPC/JSONRPC API to search any fields that you can do using the query.cgi advanced UI. The same query parameters work with either so the following:
https://bugzilla.mozilla.org/buglist.cgi?bug_status=UNCONFIRMED'&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&email1=pascalc%40gmail.com
would become:
https://bugzilla.mozilla.org/rest/bug?bug_status=UNCONFIRMED'&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&email1=pascalc%40gmail.com
The results will come back in JSON format by default.
dkl