aboutsummaryrefslogtreecommitdiffstats
path: root/lib/libbugzilla.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libbugzilla.js')
-rw-r--r--lib/libbugzilla.js178
1 files changed, 132 insertions, 46 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 14fd675..6d556a4 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -1,4 +1,3 @@
-/*jslint rhino: true, forin: true, onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: false, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
//
@@ -7,17 +6,23 @@ var preferences = require("preferences-service");
var prompts = require("prompts");
var clipboard = require("clipboard");
var tabs = require("tabs");
-//var logger = require("logger");
+var logger = require("logger");
var passUtils = require("passwords");
var Request = require("request").Request;
var selfMod = require("self");
var urlMod = require("url");
+var dataUtils = require("utils/data");
+var xrpc = require("xmlrpc");
+var panelMod = require("panel");
var JSONURLDefault = "https://fedorahosted.org/released"+
"/bugzilla-triage-scripts/Config_data.json";
var BTSPrefNS = "bugzilla-triage.setting.";
var BTSPassRealm = "BTSXMLRPCPass";
+var passwords = {}; // hash of passwords indexed by a hostname
+var config = exports.config = {};
+
function Message(cmd, data) {
console.log("Message: cmd = " + cmd + ", data = " + data);
this.cmd = cmd;
@@ -46,13 +51,9 @@ function parseXMLfromString (inStuff) {
* In case URL contains alias, not the real bug number, get the real bug no
* from the XML representation. Sets correct value to this.bugNo.
*
- * somewhere in RPC functions which need it, we should have
- * if (isNAN(parseInt(bugNo, 10))) {
- * getRealBugNo(bugNo, location, callback);
- * }
- * Or not
+ * This is a slow variant for bugs other than actual window
*/
-function getRealBugNo(bugNo, location, callback) {
+function getRealBugNoSlow(bugNo, location, callback) {
console.log("We have to deal with bug aliased as " + this.bugNo);
// https://bugzilla.redhat.com/show_bug.cgi?ctype=xml&id=serialWacom
Request({
@@ -72,22 +73,21 @@ function getRealBugNo(bugNo, location, callback) {
}).get();
}
-exports.getPassword = function getPassword(login, domain, callback) {
+function getPassword(login, domain) {
var passPrompt = "Enter your Bugzilla password for fixing MIME attachment types";
var switchPrompt = "Do you want to switch off features requiring password completely";
var prefName = BTSPrefNS+"withoutPassowrd";
- var domain = window.location.protocol + "//" + window.location.hostname;
var pass = passUtils.getPassword(login,
domain, BTSPassRealm);
var retObject = {
- password: null,
- withoutPass: false
+ password: null, // password string or null if no password provided
+ withoutPass: false // whether user doesn't want to use password at all
};
// pass === null means no appropriate password in the storage
if (!preferences.get(prefName,false) && (pass === null)) {
- passwordText = prompts.promptPassword(passPrompt);
+ var passwordText = prompts.promptPassword(passPrompt);
if (passwordText && passwordText.length > 0) {
passUtils.setLogin(login, passwordText, domain,
BTSPassRealm);
@@ -102,8 +102,8 @@ exports.getPassword = function getPassword(login, domain, callback) {
} else {
retObject.password = pass;
}
- callback(new Message("RetPassword", retObject));
-};
+ return retObject;
+}
exports.changeJSONURL = function changeJSONURL() {
var prfNm = BTSPrefNS+"JSONURL";
@@ -121,18 +121,21 @@ exports.changeJSONURL = function changeJSONURL() {
*
libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
worker.postMessage(pkgsMsg);
+
+ locationLoginObj: {
+ location: window.location.href,
+ login: getLogin()
+ }
*/
-exports.getInstalledPackages = function getInstalledPackages(location, config, callback) {
+exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, callback) {
var installedPackages = {};
var enabledPackages = [];
+ var location = locationLoginObj.location;
if (typeof location == "string") {
location = new urlMod.URL(location);
}
- console.log("location = " + location);
- console.log("typeof location = " + typeof location);
-
// Collect enabled packages per hostname (plus default ones)
if (config.gJSONData && ("commentPackages" in config.gJSONData)) {
if ("enabledPackages" in config.gJSONData.configData) {
@@ -172,30 +175,117 @@ exports.getInstalledPackages = function getInstalledPackages(location, config, c
}
}
+ if (config.gJSONData.commentStrings &&
+ "sentUpstreamString" in config.gJSONData.commentStrings) {
+ config.constantData.commentStrings = {};
+ config.constantData.commentStrings.sentUpstreamString =
+ config.gJSONData.commentStrings["sentUpstreamString"];
+ }
+
+ var locURL = new urlMod.URL(locationLoginObj.location);
+ var passDomain = locURL.scheme + "://" + locURL.host;
+ var passwObj = getPassword(locationLoginObj.login, passDomain);
+ // In order to avoid sending whole password to the content script,
+ // we are sending just these two Booleans.
+ config.constantData.passwordState = {
+ passAvailable: (passwObj.password !== null),
+ withoutPass: passwObj.withoutPass
+ };
+
callback(new Message("CreateButtons", {
instPkgs: installedPackages,
constData: config.constantData,
+ config: config.configData,
kNodes: config.gJSONData.configData.killNodes
}));
};
-exports.getClipboard = function getClipboard(command, cb) {
- cb(new Message("RetClipboard", {
- text: clipboard.get(),
- cmd: command
- }));
+exports.getClipboard = function getClipboard(cb) {
+ cb(clipboard.get());
+};
+
+exports.setClipboard = function setClipboard(stuff) {
+ clipboard.set(stuff, "text");
+};
+
+exports.getURL = function getURL(url, callback) {
+ Request({
+ url: url,
+ onComplete: function(response) {
+ if (response.status == 200) {
+ callback(response.text);
+ }
+ }
+ }).get();
+};
+
+exports.openStringInNewPanel = function openStringInNewPanel(inHTMLStr) {
+ openURLInNewPanel("data:text/html;charset=utf-8," +
+ inHTMLStr);
};
-exports.openURLinNewTab = function openURLinNewTab(urlStr) {
+var openURLInNewPanel = exports.openURLInNewPanel = function openURLInNewPanel(url) {
+ var panel = panelMod.Panel({
+ contentURL: url,
+ width: 640,
+ height: 640
+ });
+ panel.show();
+};
+
+var openURLInNewTab = exports.openURLInNewTab = function openURLInNewTab(url) {
+ tabs.open({
+ url: url,
+ inBackground: true,
+ onReady: function(t) {
+ t.activate();
+ }
+ });
+};
+
+exports.createUpstreamBug = function createUpstreamBug(urlStr, subject, comment) {
tabs.open({
url: urlStr,
inBackground: true,
onReady: function (t) {
+ var otherElems = t.contentDocument.forms.namedItem("Create").elements;
+ // Summary
+ otherElems.namedItem("short_desc").value = subject;
+ // Comment
+ otherElems.namedItem("comment").value = collectComments();
t.activate();
}
});
};
+// Make a XML-RPC call ... most of the business logic should stay in the content script
+exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, callback) {
+ var urlObj = urlMod.URL(url);
+ var passwObj = getPassword(login, urlObj.schema + "://" + urlObj.host);
+ if (!passwObj.password) {
+ return null; // TODO this should happen, only when user presses Escape in password prompt
+ }
+
+ var msg = new xrpc.XMLRPCMessage(method);
+ params.forEach(function (par) {
+ msg.addParameter(par);
+ });
+ msg.addParameter(login);
+ msg.addParameter(passwObj.password);
+
+ Request({
+ url: url,
+ onComplete: function(response) {
+ if (response.status == 200) {
+ var resp = parseXMLfromString(response.text);
+ callback(resp.toXMLString());
+ }
+ },
+ content: msg.xml(),
+ contentType: "text/xml"
+ }).post();
+};
+
exports.initialize = function initialize(config, callback) {
var prefName = BTSPrefNS+"JSONURL";
var urlStr = "";
@@ -229,56 +319,52 @@ exports.initialize = function initialize(config, callback) {
url: url,
onComplete: function(response) {
if (response.status == 200) {
- config.gJSONData.constantData[title] = response.json;
+ config.constantData[title] = response.json;
}
}
}).get();
});
}
- // config.logger = new logger.Logger(JSON.parse(self.data.load("bugzillalabelAbbreviations.json")));
-
- config.matches = config.gJSONData.configData.matches;
- config.skipMatches = config.matches.map(function(x) {
+ config.configData = {};
+ config.configData.matches = config.gJSONData.configData.matches;
+ config.configData.skipMatches = config.configData.matches.map(function(x) {
return x.replace("show_bug.cgi.*","((process|post)_bug|attachment)\.cgi$");
});
- config.objConstructor = {};
- // var bzType = config.gJSONData.configData.objectStyle;
- // if (bzType === "RH") {
- // config.objConstructor = require("rhbzpage").RHBugzillaPage;
- // } else if (bzType === "MoFo") {
- // }
- // config.objConstructor = require("mozillabzpage").MozillaBugzilla;
-
- // callback(config);
-
config.constantData = {};
- // TODO this is important and missing
if ("constantData" in config.gJSONData) {
config.constantData = config.gJSONData.constantData;
config.constantData.queryUpstreamBug = JSON.parse(
selfMod.data.load("queryUpstreamBug.json"));
config.constantData.XMLRPCData = JSON.parse(
selfMod.data.load("XMLRPCdata.json"));
+ config.constantData.bugzillaLabelNames =
+ JSON.parse(selfMod.data.load("bugzillalabelNames.json"));
+ config.constantData.newUpstreamBug =
+ JSON.parse(selfMod.data.load("newUpstreamBug.json"));
+ config.constantData.ProfessionalProducts =
+ JSON.parse(selfMod.data.load("professionalProducts.json"));
}
if ("CCmaintainer" in config.constantData) {
- config.defBugzillaMaintainerArr = config.constantData.CCmaintainer;
+ config.configData.defBugzillaMaintainerArr = config.constantData.CCmaintainer;
}
if ("suspiciousComponents" in config.gJSONData.configData) {
- config.suspiciousComponents = config.gJSONData.configData.suspiciousComponents;
+ config.configData.suspiciousComponents =
+ config.gJSONData.configData.suspiciousComponents;
}
if ("XorgLogAnalysis" in config.gJSONData.configData) {
- config.xorglogAnalysis = config.gJSONData.configData.XorgLogAnalysis;
+ config.configData.xorglogAnalysis =
+ config.gJSONData.configData.XorgLogAnalysis;
}
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
- // config.log = config.logger;
- // FIXME this.setUpLogging();
+ logger.initialize(JSON.parse(selfMod.data.load(
+ "bugzillalabelAbbreviations.json")));
}
}
callback();