Introducing bmo.js!

I decided I should finally figure out how to create and consume promises with the Add-on SDK, so I wrote this module to play around with them a bit.

bmo.js exposes a few functions to other addons:

bmo.bug() lets you receive a bug object from Bugzilla's REST API. Pass in a bug's ID, and you'll get back all of the bug object's default properties for that bug. You can optionally pass in a comma-delimited string of the properties you want it to return. 

// Look up bug 123456, only return the id and summary fields
var bug = require("./bmo").bug(123456, "id,summary");
// Define what happens when the promise resolves
bug.then(function success(bug) { console.log(bug.summary); }); lets you receive the results of a bug search, normally an object filled with bug objects. This function takes an object with JSON properties for your search parameters:

// Search for all Add-on SDK bugs with a P4 priorityvar search = require("./bmo").search({"product": "Add-on SDK", "priority": "P4"});search.then(function success(results) { for(i in results) { doSomething(results[i]); } });

bmo.count() lets you receive the count of bugs returned from a search query. The first parameter is the search object, just like from You can optionally pass in up to three separate fields for the bug counts to be broken into.

If no fields are used, the promise resolves directly to the bug count.

var count = require("./bmo").count({"product": "Add-on SDK", "priority": "P4"});
count.then(function success(counts) { /* counts == 26, or something like that */ });

If any of the fields are presented, the promise resolves to an object with multiple properties: data will be an array of the broken down bug counts, and you will have up to three additional properties, depending on how many fields you included: x_labels, y_labels, and z_labels, which will each be an array of descriptors based on those fields.

// Get the count of all P4 SDK bugs, broken down by severity
var count = require("./bmo").count({"product": "Add-on SDK", "priority": "P4"}, "severity");
count.then(function success(counts) {
// == [23,1,2]
// counts.x_label == [normal,minor,enhancement]

bmo.comments() lets you receive all comment objects from a given bug ID.

// Get all comments from bug 722597
var comments = require("./bmo").comments(722597);
comments.then(function success(comments) {
for(i in comments) {

This is all very early work, there's no authentication involved, so private bugs are not accessible, and everything is read-only, so you can't change bugs from it. This might change in the future, in addition to more querying features being added.

Many thanks to Irakli for helping me figure out what I was doing wrong while trying to consume the promises. Without his help, I'd still be stuck trying to play around with the promises, instead of actually writing the functions in the module.