main.js
Summary
No overview generated for 'main.js'
"use strict";
var util = require("util");
var logger = require("logger");
var myStorage = require("simple-storage").storage;
var browser = require("tab-browser");
var urlMod = require("url");
var JSONURL = "http://matej.ceplovi.cz/progs/data/RH_Data-packages.json";
var TriagedDistro = 13;
var NumberOfFrames = 7;
var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi";
var config = {};
config.matches = [
"https://bugzilla.redhat.com/show_bug.cgi",
"https://bz-web2-test.devel.redhat.com/show_bug.cgi",
"https://bugzilla.mozilla.org/show_bug.cgi"
];
config.skipMatches = [
"https://bugzilla.redhat.com/(process|post)_bug.cgi",
"https://bz-web2-test.devel.redhat.com/(process|post)_bug.cgi",
"https://bugzilla.mozilla.org/post_bug.cgi",
"https://bugzilla.mozilla.org/process_bug.cgi",
"https://bugzilla.(redhat.com|mozilla.org)/attachment.cgi$"
];
var WillBemanifest = {
settings : [
{
name : "BZpassword",
type : "password",
label : "Bugzilla password"
},
{
name : "JSONURL",
type : "text",
label : "Configuration file URL",
"default" : "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json"
},
{
name : "enabledPacks",
type : "text",
label : "comment packs which should be enabled",
"default" : ""
}
]
};
function isOurPage(window, matchingURLs) {
var url = window.location.href;
return matchingURLs.some(function (element,i,a) {
return new RegExp(element).test(url);
});
}
function skipThisPage(doc) {
var stemURL = "https://HOSTNAME/show_bug.cgi?id=";
var titleStr = doc.getElementsByTagName("title")[0].textContent;
var REArr = new RegExp("[bB]ug\\s+([0-9]+)").exec(titleStr);
var hostname = urlMod.URL(doc.location.href).host;
if (REArr) {
var bugNo = REArr[1];
console.log("bugNo = " + bugNo + ", hostname = " + hostname);
var emailsSent = doc.
querySelector("#bugzilla-body > dl:nth-of-type(1)").textContent;
emailsSent = emailsSent.replace(/^(\s*)$/mg,"");
util.notification(emailsSent);
doc.location = stemURL.replace("HOSTNAME",hostname) + bugNo;
}
}
function initialize(callback) {
util.loadJSON(JSONURL, function(parsedData) {
config.gJSONData = parsedData;
var keys = "", key = "";
for (key in config.gJSONData) {
keys += key + " ";
}
console.log("loaded JSON object keys: " + keys);
if ("PCIIDsURL" in config.gJSONData.configData) {
util.loadJSON(config.gJSONData.configData.PCIIDsURL, function(response) {
config.PCI_ID_Array = response;
});
}
if (!myStorage.logs) {
console.log("myStorage.logs empty!");
myStorage.logs = {};
}
var logConstructor = logger.Logger;
config.logger = new logConstructor(myStorage.logs,
config.gJSONData.constantData.bugzillalabelAbbreviations);
callback(config);
}, this);
}
exports.main = function main(options, callbacks) {
initialize(function (config) {
browser.whenContentLoaded(
function(window) {
if ("window" in window) { window = window.window; }
var construct = {};
var bzType = config.gJSONData.configData.objectStyle;
if (bzType === "RH") {
construct = require("rhbzpage").RHBugzillaPage;
} else if (bzType === "MoFo") {
construct = require("mozillabzpage").MozillaBugzilla;
}
if (isOurPage(window, config.matches)) {
var curPage = new construct(window, config);
} else if (isOurPage(window, config.skipMatches)) {
skipThisPage(window.document);
} else {
console.log("Not our page: " + window.location.href);
}
}
);
});
};
Documentation generated by
JSDoc on Wed Jun 23 09:33:14 2010