aboutsummaryrefslogtreecommitdiffstats
path: root/lib/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/main.js')
-rw-r--r--lib/main.js190
1 files changed, 100 insertions, 90 deletions
diff --git a/lib/main.js b/lib/main.js
index fbabd41..accaa0e 100644
--- a/lib/main.js
+++ b/lib/main.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
//
@@ -11,17 +10,13 @@
// http://ehsanakhgari.org/blog/2010-05-31/my-experience-jetpack-sdk#comment-1253
//
"use strict";
-var logger = require("logger");
var browser = require("tab-browser");
-var selfMod = require("self");
-var Request = require("request").Request;
-var preferences = require("preferences-service");
-var BTSPrefNS = require("bzpage").BTSPrefNS;
-// Use my JSON for now before it is fixed for general public
-var JSONURLDefault = "https://fedorahosted.org/released"+
- "/bugzilla-triage-scripts/Config_data.json";
-
-var config = {};
+var self = require("self");
+var pageMod = require("page-mod");
+var libbz = require("libbugzilla");
+var tabs = require("tabs");
+var logger = require("logger");
+var Message = require("util").Message;
function isOurPage(window, matchingURLs) {
var url = window.location.href;
@@ -47,88 +42,103 @@ function skipThisPage(doc) {
}
}
-function initialize(callback) {
- var prefName = BTSPrefNS+"JSONURL";
- var urlStr = "";
-
- if (preferences.isSet(prefName)) {
- urlStr = preferences.get(prefName);
- } else {
- urlStr = JSONURLDefault;
- preferences.set(prefName, JSONURLDefault);
+var messageHandler = exports.messageHandler = function messageHandler(worker, msg) {
+ switch (msg.cmd) {
+ case "LogMessage":
+ console.log(msg.data);
+ break;
+ case "ExecCmd":
+ libbz.executeCommand(msg.data);
+ break;
+ case "AddLogRecord":
+ logger.addLogRecord(msg.data);
+ break;
+ case "GenerateTS":
+ logger.generateTimeSheet();
+ break;
+ case "ClearTS":
+ logger.clearTimeSheet();
+ break;
+ case "ImportTS":
+ logger.importTimeSheet();
+ break;
+ case "GetInstalledPackages":
+ // send message with packages back
+ libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
+ worker.postMessage(pkgsMsg);
+ });
+ break;
+ case "GetClipboard":
+ libbz.getClipboard(function (clipboard) {
+ worker.postMessage(new Message(msg.data, clipboard));
+ });
+ break;
+ case "ChangeJSONURL":
+ libbz.changeJSONURL();
+ break;
+ case "OpenURLinPanel":
+ libbz.openURLInNewPanel(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,
+ msg.data.params, function(ret) {
+ worker.postMessage(new Message(msg.data.callRPC, ret));
+ });
+ 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;
+ default:
+ console.error(msg.toSource());
}
+};
- // Randomize URL to avoid caching
- // TODO see https://fedorahosted.org/bugzilla-triage-scripts/ticket/21
- // for more thorough discussion and possible further improvement
- urlStr += (urlStr.match(/\?/) == null ? "?" : "&") + (new Date()).getTime();
-
- Request({
- url: urlStr,
- onComplete: function (response) {
- if (response.status == 200) {
- config.gJSONData = response.json;
-
- // Get additional tables
- if ("downloadJSON" in config.gJSONData.configData) {
- var URLsList = config.gJSONData.configData.downloadJSON;
- var dwnldObj = "";
- URLsList.forEach(function (arr) {
- var title = arr[0];
- var url = arr[1];
- Request({
- url: url,
- onComplete: function(response) {
- if (response.status == 200) {
- config.gJSONData.constantData[title] = response.json;
- }
- }
- }).get();
- }, this);
- }
-
- config.logger = new logger.Logger(JSON.parse(selfMod.data.load("bugzillalabelAbbreviations.json")));
-
- config.matches = config.gJSONData.configData.matches;
- config.skipMatches = config.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;
- }
+var contentScriptLibraries = {
+ "bugzilla.redhat.com": [
+ self.data.url("lib/util.js"),
+ self.data.url("lib/color.js"),
+ self.data.url("lib/rhbzpage.js"),
+ self.data.url("lib/bzpage.js")
+ ]
+};
- callback(config);
- }
+libbz.initialize(libbz.config, function () {
+ pageMod.PageMod({
+ include: [
+ "https://bugzilla.redhat.com/show_bug.cgi?id=*"
+ ],
+ contentScriptWhen: 'ready',
+ contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"],
+ onAttach: function onAttach(worker, msg) {
+ worker.on('message', function (msg) {
+ messageHandler(worker, msg);
+ });
}
- }).get();
-}
+ });
+});
-exports.main = function main(options, callbacks) {
- initialize(function (config) {
- browser.whenContentLoaded(
- function(window) {
- // is this good for anything?
- if ("window" in window) { window = window.window; }
+pageMod.PageMod({
+ include: [
+ "https://bugzilla.redhat.com/process_bug.cgi",
+ "https://bugzilla.redhat.com/attachment.cgi"
+ ],
+ contentScriptWhen: 'ready',
+ contentScriptFile: self.data.url("lib/skip-bug.js")
+});
- if (isOurPage(window, config.matches)) {
- try {
- var curPage = new config.objConstructor(window, config);
- } catch (ex) {
- if (ex instanceof require("bzpage").NotLoggedinException) {
- return ; // Bail out if the user is not logged in
- } else {
- throw ex; // rethrow the exception otherwise
- }
- }
- } else if (isOurPage(window, config.skipMatches)) {
- skipThisPage(window.document);
- }
- }
- );
- });
-};
+// tabs.open("https://bugzilla.redhat.com/show_bug.cgi?id=679515");