aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libbugzilla.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libbugzilla.js')
-rw-r--r--lib/libbugzilla.js67
1 files changed, 42 insertions, 25 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 990c759..ae4ea01 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -26,6 +26,7 @@ var copiedAttributes = [ "queryButton", "upstreamButton", "parseAbrtBacktraces",
var passwords = {}; // hash of passwords indexed by a hostname
var config = exports.config = {};
+var debugOption = false;
function Message(cmd, data) {
console.log("Message: cmd = " + cmd + ", data = " + data);
@@ -37,6 +38,12 @@ function log(msg) {
postMessage(new Message("LogMessage", msg));
}
+function debug(str) {
+ if (debugOption) {
+ console.log(str);
+ }
+}
+
/**
* parse XML object out of string working around various bugs in Gecko
* implementation see https://developer.mozilla.org/en/E4X for more information
@@ -61,7 +68,7 @@ function parseXMLfromString (inStuff) {
* This is a slow variant for bugs other than actual window
*/
function getRealBugNoSlow(bugNo, location, callback) {
- console.log("We have to deal with bug aliased as " + this.bugNo);
+ debug("We have to deal with bug aliased as " + this.bugNo);
// https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=serialWacom
Request({
url: location.href+"&ctype=xml",
@@ -73,7 +80,7 @@ function getRealBugNoSlow(bugNo, location, callback) {
if (isNaN(bugID)) {
throw new Error("Cannot get bug no. even from XML representation!");
}
- console.log("The real bug no. is " + bugID);
+ debug("The real bug no. is " + bugID);
callback(bugID)
}
}
@@ -133,7 +140,7 @@ function getPassword(login, domain, callback) {
exports.changeJSONURL = function changeJSONURL() {
var prfNm = BTSPrefNS+"JSONURL";
- var url = preferences.get(prfNm,"");
+ var url = preferences.get(prfNm, JSONURLDefault);
var reply = prompts.prompt("New location of JSON configuration file", url);
if (reply && (reply != url)) {
@@ -287,7 +294,7 @@ exports.createUpstreamBug = function createUpstreamBug(urlStr, subject, comment)
exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, callback) {
var urlObj = urlMod.URL(url);
getPassword(login,
- urlObj.schema + "://" + urlObj.host,
+ urlObj.scheme + "://" + urlObj.host,
function (passwObj) {
if (!passwObj.password) {
// TODO this should happen, only when user presses Escape in password
@@ -317,25 +324,46 @@ exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, cal
);
};
+exports.makeJSONRPCCallWithLogin = function makeJSONRPCCallWithLogin(url, method, params,
+ login, callback) {
+ var urlObj = urlMod.URL(url);
+ getPassword(login,
+ urlObj.scheme + "://" + urlObj.host,
+ function (passObj) {
+ if (!passObj.password) {
+ return;
+ }
+
+ makeJSONRPCCall(url, "User.login", {
+ login: login,
+ password: passObj.password,
+ remember: false
+ }, function(logResult) {
+ console.log("logResult = " + logResult.toSource());
+ makeJSONRPCCall(url, method, params, callback);
+ });
+ }
+ );
+};
+
// Make a JSONL-RPC call ... most of the business logic should stay in the
// content script
// http://json-rpc.org/wd/JSON-RPC-1-1-WD-20060807.html
-exports.makeJSONRPCCall = function makeJSONRPCCall(url, method, params, callback) {
+var makeJSONRPCCall = exports.makeJSONRPCCall = function makeJSONRPCCall(url, method, params, callback) {
-// {"version":"1.1", "method":"Bug.history", "params":{ "ids":[12345] } }
var msg = {
"version": "1.1",
"method": method,
"params": params
};
-// console.log("makeJSONRPCCall: out = " + JSON.stringify(msg));
+ debug("makeJSONRPCCall: out = " + JSON.stringify(msg));
Request({
url: url,
onComplete: function(response) {
if (response.status == 200) {
-// console.log("makeJSONRPCCall: in = " + response.text);
+ debug("makeJSONRPCCall: in = " + response.text);
callback(response.json.result);
}
},
@@ -346,24 +374,13 @@ exports.makeJSONRPCCall = function makeJSONRPCCall(url, method, params, callback
exports.initialize = function initialize(config, callback) {
var prefJSONURLName = BTSPrefNS+"JSONURL";
- var prefDebugName = BTSPrefNS+"debug";
- var urlStr = "",
- debugOption = false; // should we spit out a lot of debugging output
+ var urlStr = preferences.get(prefJSONURLName, JSONURLDefault);
+ preferences.set(prefJSONURLName, urlStr);
- if (preferences.isSet(prefJSONURLName)) {
- urlStr = preferences.get(prefJSONURLName);
- }
- else {
- urlStr = JSONURLDefault;
- preferences.set(prefJSONURLName, JSONURLDefault);
- }
-
- if (preferences.isSet(prefDebugName)) {
- debugOption = preferences.get(prefDebugName);
- }
- else {
- preferences.set(prefDebugName, debugOption);
- }
+ // should we spit out a lot of debugging output
+ var prefDebugName = BTSPrefNS+"debug";
+ debugOption = preferences.get(prefDebugName, false);
+ preferences.set(prefDebugName, debugOption);
// Randomize URL to avoid caching
// TODO see https://fedorahosted.org/bugzilla-triage-scripts/ticket/21