aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libbugzilla.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libbugzilla.js')
-rw-r--r--lib/libbugzilla.js92
1 files changed, 33 insertions, 59 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 7458601..18cd2b5 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -290,6 +290,17 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subjectStr, comme
});
};
+
+function processPageModeREs() {
+ var confD = config.configData;
+ ['bugPageMatch', 'skipMatch'].forEach(function (key) {
+ confD[key] = confD[key+"Str"].map(function (REStr) {
+ return new RegExp(REStr);
+ });
+ });
+}
+
+
function loginToAllBugzillas(callback) {
var loginCallsCounter = 0, bugzilla = "";
@@ -308,6 +319,8 @@ function loginToAllBugzillas(callback) {
onComplete: function onComplete(credentials) {
// (we can have more than one set of credentials per bugzilla;
// well, theoretically)
+ debug("loginToAllBugzillas: credentials found:\n" +
+ credentials.toSource());
credentials.forEach(function(credential) {
// ... login!
makeJSONRPCCall(credential.url + "/jsonrpc.cgi",
@@ -365,21 +378,13 @@ var makeJSONRPCCall = exports.makeJSONRPCCall = function makeJSONRPCCall(url, me
}).post();
};
-function processPageModeREs() {
- var confD = config.configData;
- ['bugPageMatch', 'skipMatch'].forEach(function (key) {
- confD[key] = confD[key+"Str"].map(function (REStr) {
- return new RegExp(REStr);
- });
- });
-}
-
/**
* Preprocess JSON into config data structure.
*
* Should be completely side-effects free pure function.
*/
function processConfigJSON(rawJSON) {
+ var config = {};
config.gJSONData = rawJSON;
var origConstData = config.gJSONData.configData;
@@ -430,12 +435,12 @@ function processConfigJSON(rawJSON) {
});
}
else {
- config.configData.bugPageMatch = origConstData.matches;
- config.configData.skipMatch = [];
+ config.configData.bugPageMatchStr = origConstData.matches;
+ config.configData.skipMatchStr = [];
origConstData.matches.
forEach(function(x) {
skippingURLParts.forEach(function (part) {
- config.configData.skipMatch.push(x.
+ config.configData.skipMatchStr.push(x.
replace("show_bug.cgi.*", part + ".cgi"));
});
});
@@ -466,28 +471,30 @@ function processConfigJSON(rawJSON) {
config.configData[attrib] = origConstData[attrib];
}
});
+
+ return(config);
}
+function ConfigurationLoadError(msg) {
+ this.name = "ConfigurationLoadError";
+ this.message = msg || "Cannot load configuration!";
+}
+ConfigurationLoadError.prototype = new Error();
+ConfigurationLoadError.constructor = ConfigurationLoadError;
+
+
function fetchConfigurationJSON(url, callback) {
+ debug("Fetching configuration JSON from " + url);
var retValue = null;
Request({
url: url,
onComplete: function (response) {
if (response.status == 200) {
- processConfigJSON(response.json);
- myStorage.storage.configJSON.meta.eTag = response.headers['Etag'];
- myStorage.storage.configJSON.meta.lastModified =
- response.headers['Last-Modified'];
- myStorage.storage.configJSON.parsedJSON = config;
+ config = processConfigJSON(response.json);
+ debug("Loaded configuration: " + config);
}
else {
- // If we cannot get JSON from the real URL, we are happy
- // with getting our fix from anywhere, including (possibly)
- // expired cache
- if (myStorage.storage.configJSON &&
- myStorage.storage.configJSON.parsedJSON) {
- config = myStorage.storage.configJSON.parsedJSON;
- }
+ throw new ConfigurationLoadError("Cannot load configuration from " + url);
}
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
@@ -503,39 +510,6 @@ exports.initialize = function initialize(callback) {
var urlStr = preferences.get(prefJSONURLName, JSONURLDefault);
preferences.set(prefJSONURLName, urlStr);
- if (!myStorage.storage.configJSON) {
- myStorage.storage.configJSON = {};
- myStorage.storage.configJSON.meta = {
- eTag: "",
- lastModified: null
- };
- }
-
- var req = new xhrMod.XMLHttpRequest();
- req.open("HEAD", urlStr, true);
- req.onreadystatechange = function (aEvt) {
- if (req.readyState == 4) {
- if(req.status == 200) {
- var _curETag = req.getResponseHeader("ETag");
- var _curLastModified = new Date(req.getResponseHeader("Last-Modified"));
- if ((_curETag == myStorage.storage.configJSON.meta.eTag)
- || (_curLastModified <=
- myStorage.storage.configJSON.meta.lastModified)) {
- debug("Loading from cache!");
- // use cached values
- config = myStorage.storage.configJSON.parsedJSON;
- if ("submitsLogging" in config.gJSONData.configData &&
- config.gJSONData.configData.submitsLogging) {
- logger.initialize();
- }
- loginToAllBugzillas(callback);
- }
- else { // cache is not up-to-date
- debug("Too old cache!");
- fetchConfigurationJSON(urlStr, callback);
- }
- }
- }
- };
- req.send();
+ debug("Starting initialize!");
+ fetchConfigurationJSON(urlStr, callback);
}