aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-02-10 18:24:18 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-02-10 18:24:18 +0100
commit838c1d4abd72bd87dcc8ee41310ca3a8af498c96 (patch)
treef22b0cf123a08fc51c3c779ee5b0971aa2a174c0 /lib
parentba0b4d6110e5b50c15ce722a5a123bcf26bafe3e (diff)
downloadbugzilla-triage-838c1d4abd72bd87dcc8ee41310ca3a8af498c96.tar.gz
All functions should be (theoretically) either working or commented out.
Diffstat (limited to 'lib')
-rw-r--r--lib/libbugzilla.js88
-rw-r--r--lib/main.js27
2 files changed, 86 insertions, 29 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index 337a72e..41aa27a 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -11,6 +11,7 @@ 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");
@@ -20,6 +21,7 @@ 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);
@@ -125,7 +127,7 @@ exports.changeJSONURL = function changeJSONURL() {
login: getLogin()
}
*/
-exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, config, callback) {
+exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, callback) {
var installedPackages = {};
var enabledPackages = [];
var location = locationLoginObj.location;
@@ -177,6 +179,12 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
}
}
+ if ("sentUpstreamString" in config.gJSONData.commentStrings) {
+ config.constantData.commentStrings = {};
+ config.constantData.commentStrings.sentUpstreamString =
+ config.gJSONData.commentStrings["sentUpstreamString"];
+ }
+
// Investigate situation about password
/*
passwObj = {
@@ -185,7 +193,7 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
}; */
var locURL = new urlMod.URL(locationLoginObj.location);
var passDomain = locURL.scheme + "://" + locURL.host;
- passwObj = getPassword(locationLoginObj.login, passDomain);
+ 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 = {
@@ -196,31 +204,60 @@ exports.getInstalledPackages = function getInstalledPackages(locationLoginObj, c
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.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," +
+ dataUtils.base64Encode(inHTMLStr));
};
exports.openURLInNewPanel = function openURLInNewPanel(url) {
- panelMod.Panel({
+ var panel = panelMod.Panel({
contentURL: url,
width: 640,
- height: 640,
- allow: false // TODO needs to be reviewed
+ height: 640
});
-}
+ panel.show();
+};
+
+exports.openURLInNewTab = function openURLInNewTab(url) {
+ tabs.open({
+ url: url,
+ inBackground: true,
+ onReady: function(t) {
+ t.activate();
+ }
+ });
+};
-exports.openURLinNewTab = function openURLinNewTab(urlStr) {
+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();
}
});
@@ -257,7 +294,6 @@ exports.makeXMLRPCCall = function makeXMLRPCCall(url, login, method, params, cal
exports.initialize = function initialize(config, callback) {
var prefName = BTSPrefNS+"JSONURL";
var urlStr = "";
- var passwObj = {};
if (preferences.isSet(prefName)) {
urlStr = preferences.get(prefName);
@@ -295,14 +331,16 @@ exports.initialize = function initialize(config, callback) {
});
}
- // config.logger = new logger.Logger(JSON.parse(self.data.load("bugzillalabelAbbreviations.json")));
+ // 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 = {};
+ // config.objConstructor = {};
// var bzType = config.gJSONData.configData.objectStyle;
// if (bzType === "RH") {
// config.objConstructor = require("rhbzpage").RHBugzillaPage;
@@ -310,8 +348,6 @@ exports.initialize = function initialize(config, callback) {
// }
// config.objConstructor = require("mozillabzpage").MozillaBugzilla;
- // callback(config);
-
config.constantData = {};
// TODO this is important and missing
if ("constantData" in config.gJSONData) {
@@ -320,18 +356,26 @@ exports.initialize = function initialize(config, callback) {
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 &&
diff --git a/lib/main.js b/lib/main.js
index 5ba237d..abdc758 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -12,14 +12,11 @@
"use strict";
var browser = require("tab-browser");
var self = require("self");
-var Request = require("request").Request;
var pageMod = require("page-mod");
var libbz = require("libbugzilla");
var tabs = require("tabs");
var logger = require("logger");
-var config = {};
-
function isOurPage(window, matchingURLs) {
var url = window.location.href;
@@ -67,13 +64,13 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms
break;
case "GetInstalledPackages":
// send message with packages back
- libbz.getInstalledPackages(msg.data, config, function (pkgsMsg) {
+ libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
worker.postMessage(pkgsMsg);
});
break;
case "GetClipboard":
- libbz.getClipboard(msg.data, function (clipboard) {
- worker.postMessage(clipboard);
+ libbz.getClipboard(function (clipboard) {
+ worker.postMessage(new Message(msg.data, clipboard));
});
break;
case "ChangeJSONURL":
@@ -82,6 +79,12 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms
case "OpenURLinPanel":
libbz.openURLinPanel(msg.data);
break;
+ case "OpenURLinTab":
+ libbz.openURLInNewTab(msg.data);
+ break;
+ case "OpenStringInPanel":
+ libbz.openStringInNewPanel(msg.data);
+ break;
case "MakeXMLRPCall":
// url, login, method, params, callback
libbz.makeXMLRPCCall(msg.data.url, msg.data.login, msg.data.method,
@@ -92,6 +95,14 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms
});
});
break;
+ case "GetURL":
+ libbz.getURL(msg.data.url, function(stuff) {
+ worker.postMessage(new Message(msg.data.backMessage, stuff));
+ });
+ break;
+ case "OpenBugUpstream":
+ libbz.createUpstreamBug(msg.data.url, msg.data.subject, msg.data.comment);
+ break;
case "testReady":
// we ignore it here, interesting only in unit test
break;
@@ -109,7 +120,7 @@ var contentScriptLibraries = {
]
};
-libbz.initialize(config, function () {
+libbz.initialize(libbz.config, function () {
pageMod.PageMod({
include: [
"https://bugzilla.redhat.com/show_bug.cgi?id=*"
@@ -124,3 +135,5 @@ libbz.initialize(config, function () {
}
});
});
+
+tabs.open("https://bugzilla.redhat.com/show_bug.cgi?id=595017");