// Bugzilla: https://wiki.mozilla.org/Bugzilla:REST_API (and https://github.com/harthur/bz.js?)

const https = require('https');

exports.config = {
  email: {
    doc: "Bugzilla email",
    format: 'string'
  }
};

exports.print = function () {
  // TODO: fetch private bugs too
  var options = {
    hostname: 'api-dev.bugzilla.mozilla.org',
    port: 443,
    path: '/1.1/bug?email1=' + conf.get('bugzilla').email + '&email1_type=equals_any&email1_assigned_to=1&email1_qa_contact=1&email1_cc=1&status=UNCONFIRMED&status=NEW&status=ASSIGNED&status=REOPENED&include_fields=id,summary',
    method: 'GET'
  };
  var req = https.request(options, function (res) {
    var bugData = '';
    res.on('data', function (chunk) {
      bugData += chunk;
    });

    res.on('end', function () {
      process.stdout.write("BUGZILLA BUGS\n");

      var bugs = JSON.parse(bugData).bugs;
      bugs.forEach(function (bug) {
        var bugID = bug.id;
        var bugSummary = bug.summary;
        process.stdout.write("  " + bugID + ": " + bugSummary + "\n");
      });
    });
  });
  req.end();

  req.on('error', function (e) {
    console.error(e);
  });
};

@@ -213,34 +213,158 @@
 %7D;%0A%0A
-exports.print = function (
+var bugzillaBugs = %7B%0A  blocker: %5B%5D,%0A  critical: %5B%5D,%0A  major: %5B%5D,%0A  normal: %5B%5D,%0A  minor: %5B%5D,%0A  trivial: %5B%5D,%0A  enhancement: %5B%5D%0A%7D;%0A%0Afunction fetchBugs(cb
 ) %7B%0A
@@ -397,16 +397,37 @@
 ugs too%0A
+  var bugCount = 0;%0A%0A
   var op
@@ -722,16 +722,32 @@
 ,summary
+,severity,status
 ',%0A    m
@@ -1080,229 +1080,707 @@
     
-var bugID = bug.id;%0A        var
+bugzillaBugs%5Bbug.severity%5D.push(%7Bid: bug.id, summary:
  bug
-S
+.s
 ummary
- = bug.summary;%0A        process.stdout.write(%22  %22 + bugID + %22: %22 + bugSummary + %22%5Cn%22);%0A      %7D);%0A    %7D);%0A  %7D);%0A  req.end();%0A%0A  req.on('error', function (e) %7B%0A    console.error(e);
+, status: bug.status%7D);%0A        bugCount += 1;%0A        if (bugCount != bugs.length) %7B%0A          return;%0A        %7D%0A        return cb();%0A      %7D);%0A    %7D);%0A  %7D);%0A  req.end();%0A%0A  req.on('error', function (e) %7B%0A    console.error(e);%0A  %7D);%0A%7D%0A%0Aexports.print = function () %7B%0A  fetchBugs(function () %7B%0A    for (severity in bugzillaBugs) %7B%0A      if (!bugzillaBugs.hasOwnProperty(severity) %7C%7C bugzillaBugs%5Bseverity%5D.length %3C 1) %7B%0A        continue;%0A      %7D%0A%0A      process.stdout.write(severity + %22%5Cn%22);%0A%0A      bugzillaBugs%5Bseverity%5D.forEach(function (bug) %7B%0A        process.stdout.write(%22  %22 + bug.id + %22: %22 + bug.summary + %22%5Cn%22);%0A      %7D);%0A    %7D
 %0A  %7D

Add severity to Bugzilla bugs