Skip to content

Instantly share code, notes, and snippets.

Last active December 20, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascalchevrel/6099342 to your computer and use it in GitHub Desktop.
Save pascalchevrel/6099342 to your computer and use it in GitHub Desktop.
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…
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;
foreach ($fields as $key => $field) {
$temp[$field] = $data[$key];
$fullBugs[] = $temp;
$shortBugs[$temp['bug_id']] = $temp['short_desc'];
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 = '';
$request ='bug_status=UNCONFIRMED'
. '&bug_status=NEW'
. '&bug_status=ASSIGNED'
. '&bug_status=REOPENED'
. '&emailassigned_to1=1'
. '&';
$request .= '&ctype=csv';
$csv = $bugzillaQueryUrl . $request;
Copy link

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:'&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&

would become:'&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&

The results will come back in JSON format by default.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment