aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/libbugzilla.js43
-rw-r--r--lib/logger.js48
-rw-r--r--lib/main.js47
-rw-r--r--lib/util.js65
4 files changed, 138 insertions, 65 deletions
diff --git a/lib/libbugzilla.js b/lib/libbugzilla.js
index e074072..1c5f7a2 100644
--- a/lib/libbugzilla.js
+++ b/lib/libbugzilla.js
@@ -10,14 +10,14 @@ var tabs = require("tabs");
//var logger = require("logger");
var passUtils = require("passwords");
var Request = require("request").Request;
+var selfMod = require("self");
+var urlMod = require("url");
var JSONURLDefault = "https://fedorahosted.org/released"+
"/bugzilla-triage-scripts/Config_data.json";
var BTSPrefNS = "bugzilla-triage.setting.";
var BTSPassRealm = "BTSXMLRPCPass";
-var config = {};
-
function Message(cmd, data) {
console.log("Message: cmd = " + cmd + ", data = " + data);
this.cmd = cmd;
@@ -122,20 +122,23 @@ exports.changeJSONURL = function changeJSONURL() {
libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
worker.postMessage(pkgsMsg);
*/
-exports.getInstalledPackages = function getInstalledPackages(location, callback) {
+exports.getInstalledPackages = function getInstalledPackages(location, config, callback) {
var installedPackages = {};
var enabledPackages = [];
- console.log("location = " + location.toString());
- console.log("location = " + typeof 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)
- console.log("getInstalledPackages: config = " + config.toSource());
if (config.gJSONData && ("commentPackages" in config.gJSONData)) {
if ("enabledPackages" in config.gJSONData.configData) {
var epObject = config.gJSONData.configData.enabledPackages;
- if (location.hostname in epObject) {
- enabledPackages = enabledPackages.concat(epObject[location.hostname].split(/[,\s]+/));
+ if (location.host in epObject) {
+ enabledPackages = enabledPackages.concat(epObject[location.host].split(/[,\s]+/));
}
if ("any" in epObject) {
enabledPackages = enabledPackages.concat(epObject.any.split(/[,\s]+/));
@@ -149,12 +152,9 @@ exports.getInstalledPackages = function getInstalledPackages(location, callback)
}
}
- console.log("getInstalledPackages: enabledPackages = " + enabledPackages.toSource());
-
// TODO To be decided, whether we cannot just eliminate packages in
// installedPackages and having it just as a plain list of all cmdObjects.
enabledPackages.forEach(function (pkg, idx, arr) {
- console.log("getInstalledPackages: pkg = " + pkg);
if (pkg in config.gJSONData.commentPackages) {
installedPackages[pkg] = config.gJSONData.commentPackages[pkg];
}
@@ -162,23 +162,21 @@ exports.getInstalledPackages = function getInstalledPackages(location, callback)
}
// Expand commentIdx properties into full comments
- console.log("before // installedPackages = " + installedPackages.toSource());
var cmdObj = {};
for (var pkgKey in installedPackages) {
for (var cmdObjKey in installedPackages[pkgKey]) {
cmdObj = installedPackages[pkgKey][cmdObjKey];
if ("commentIdx" in cmdObj) {
- cmdObj.comment = config.commentStrings[cmdObj.commentIdx];
+ cmdObj.comment = config.gJSONData.commentStrings[cmdObj.commentIdx];
delete cmdObj.commentIdx;
}
}
}
- console.log("after // installedPackages = " + installedPackages.toSource());
-
callback(new Message("CreateButtons", {
instPkgs: installedPackages,
- constData: config.constantData
+ constData: config.constantData,
+ kNodes: config.gJSONData.configData.killNodes
}));
};
@@ -199,7 +197,7 @@ exports.openURLinNewTab = function openURLinNewTab(urlStr) {
});
};
-function initialize() {
+exports.initialize = function initialize(config, callback) {
var prefName = BTSPrefNS+"JSONURL";
var urlStr = "";
@@ -239,7 +237,7 @@ function initialize() {
});
}
- 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) {
@@ -280,16 +278,9 @@ function initialize() {
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
- config.log = config.logger;
+ // config.log = config.logger;
// FIXME this.setUpLogging();
}
-
- if ("killNodes" in config.gJSONData.configData &&
- window.location.hostname in config.gJSONData.configData.killNodes) {
- var killConf = config.gJSONData.configData.killNodes[window.location.hostname];
- killNodes(config.doc, killConf[0], killConf[1]);
- }
-
}
callback();
}
diff --git a/lib/logger.js b/lib/logger.js
index cbe670d..659faac 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -10,6 +10,29 @@ var apiUtils = require("api-utils");
var xrpc = require("xmlrpc");
var myStorage = require("simple-storage");
+exports.addLogRecord = function addLogRecord(rec) {
+ if (myStorage.storage.logs[rec.key]) {
+ myStorage.storage.logs[rec.key].comment += "<br/>\n" + comment;
+ } else {
+ myStorage.storage.logs[rec.key] = rec;
+ }
+};
+
+exports.generateTimeSheet = function generateTimeSheet() {
+ ; // FIXME
+};
+
+exports.clearTimeSheet = function clearTimeSheet() {
+ ; // FIXME
+};
+
+exports.importTimeSheet = function importTimeSheet() {
+ ; /* FIXME
+ jsonPaths = prompts.promptFileOpenPicker(that.win);
+ that.log.importOtherStore(jsonPaths, clearLogAElem);
+ */
+};
+
var Logger = exports.Logger = function Logger(abbsMap) {
this.EmptyLogsColor = rgb(0, 255, 0);
this.FullLogsColor = rgb(0, 40, 103);
@@ -59,31 +82,6 @@ Logger.prototype.importOtherStore = function importOtherStore (filename, clearLi
}
};
-Logger.prototype.addLogRecord = function addLogRecord(page) {
- var rec = {};
- rec.date = new Date();
- rec.url = page.doc.location.toString();
- rec.title = page.title;
- var comment = prompts.prompt(
- "Enter comments for this comment");
- if (comment && comment.length > 0) {
- comment = comment.trim();
- rec.comment = comment;
- var dateStr = utilMod.getISODate(rec.date);
- var urlStr = urlMod.URL(rec.url).host;
- var recKey = dateStr + "+"
- + urlStr
- + "+" + page.bugNo;
-
- if (myStorage.storage.logs[recKey]) {
- myStorage.storage.logs[recKey].comment += "<br/>\n" + comment;
- } else {
- myStorage.storage.logs[recKey] = rec;
- }
- }
- return comment;
-};
-
Logger.prototype.getBugzillaAbbr = function(url) {
// for https://bugzilla.redhat.com/show_bug.cgi?id=579123 get RH
// for https://bugzilla.mozilla.org/show_bug.cgi?id=579123 get MoFo
diff --git a/lib/main.js b/lib/main.js
index 0afa67d..bf34514 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -16,6 +16,10 @@ 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;
@@ -50,10 +54,22 @@ var messageHandler = exports.messageHandler = function messageHandler(worker, ms
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
console.log("msg = " + msg.toSource());
- libbz.getInstalledPackages(msg.data, function (pkgsMsg) {
+ libbz.getInstalledPackages(msg.data, config, function (pkgsMsg) {
worker.postMessage(pkgsMsg);
});
break;
@@ -85,17 +101,20 @@ var contentScriptLibraries = {
]
};
-libbz.initialize();
-pageMod.PageMod({
- include: [
- "https://bugzilla.redhat.com/show_bug.cgi?id=*"
- ],
- contentScriptWhen: 'ready',
- contentScriptFile: contentScriptLibraries["bugzilla.redhat.com"],
- onAttach: function onAttach(worker, msg) {
- console.log("worker: " + worker);
- worker.on('message', function (msg) {
- messageHandler(worker, msg);
- });
- }
+libbz.initialize(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) {
+ console.log("worker: " + worker);
+ worker.on('message', function (msg) {
+ messageHandler(worker, msg);
+ });
+ }
+ });
});
+
+tabs.open("https://bugzilla.redhat.com/show_bug.cgi?id=673153");
diff --git a/lib/util.js b/lib/util.js
new file mode 100644
index 0000000..8556951
--- /dev/null
+++ b/lib/util.js
@@ -0,0 +1,65 @@
+/*global exports: false, require: false, console: false, Cc: false, Ci: false */
+/*jslint onevar: false */
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+"use strict";
+// ==============================================================
+var Cc = require("chrome").Cc;
+var Ci = require("chrome").Ci;
+var urlMod = require("url");
+
+/**
+ * get parameters of URL as an object (name, value)
+ */
+function getParamsFromURL (url, base) {
+ if (!url || (url.toString().length === 0)) {
+ throw new Error("Missing URL value!");
+ }
+
+ if (!(url instanceof urlMod.URL)) {
+ url = new urlMod.URL(url.toString(), base);
+ }
+
+ var paramsArr = url.path.split("?");
+ if (paramsArr.length === 1) {
+ return {};
+ }
+
+ // get convert URL parameters to an Object
+ var params = {}, s = [];
+ paramsArr[1].split('&').forEach(function(par) {
+ s = par.split('=');
+ params[s[0]] = s[1];
+ });
+ return params;
+}
+
+/**
+ * Get a bug no from URL ... fails with aliases
+ * It should theoretically belong to bzpage.js, but we don't have
+ * unit tests there yet, so keeping here.
+ *
+ * @param url String with URL to be analyzed
+ * @return String with the bug ID (hopefully number, but not for aliases)
+ */
+exports.getBugNo = function getBugNo(url) {
+ var params = getParamsFromURL(url);
+ if (params && params.id) {
+ return params.id;
+ }
+};
+
+/**
+ * format date to be in ISO format (just day part)
+ *
+ * @param date
+ * @return string with the formatted date
+ */
+exports.getISODate = function getISODate(dateStr) {
+ function pad(n) {
+ return n < 10 ? '0' + n : n;
+ }
+ var date = new Date(dateStr);
+ return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' +
+ pad(date.getDate());
+};