aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/bzpage.js109
-rw-r--r--lib/logger.js19
-rw-r--r--lib/main.js6
-rw-r--r--lib/rhbzpage.js106
-rw-r--r--lib/util.js136
5 files changed, 242 insertions, 134 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 329165d..042a19e 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -1,11 +1,11 @@
/*jslint onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
-/*global jetpack */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
"use strict";
var util = require("util");
var apiUtils = require("api-utils");
var simpleStorage = require("simple-storage");
+var preferences = require("preferences-service");
var Color = require("color").Color;
var TriagedDistro = 13;
@@ -16,8 +16,6 @@ var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id=";
// ====================================================================================
// BZPage's methods
var BZPage = function BZPage(doc, config) {
- console.log("doc = " + doc);
- console.log("config = " + config);
var keys = "";
for (var key in config) {
keys += key + ", ";
@@ -32,21 +30,22 @@ var BZPage = function BZPage(doc, config) {
// initialize dynamic properties
this.doc = doc;
this.packages = this.getInstalledPackages(config);
+
if ("commentStrings" in config.gJSONData) {
this.commentStrings = config.gJSONData.commentStrings;
}
-
if ("constantData" in config.gJSONData) {
- // this is wrong, I shouldn't bother anybody with my Xorg data, and
- // I should load it from URL
- // var stuff = JSON.parse(self.data.load("chiIDsGroupings.json"));
this.constantData = config.gJSONData.constantData;
}
if ("CCmaintainer" in config.gJSONData.constantData) {
this.defBugzillaMaintainerArr = config.gJSONData.constantData.CCmaintainer;
}
+
+ if ("suspiciousComponents" in config.gJSONData.configData) {
+ this.suspiciousComponents = config.gJSONData.configData.suspiciousComponents;
+ }
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
@@ -63,28 +62,21 @@ var BZPage = function BZPage(doc, config) {
this.version = this.getVersion();
this.title = this.doc.getElementById("short_desc_nonedit_display").textContent;
this.CCList = this.getCCList();
-
- this.packages = this.getInstalledPackages();
-
- if ("commentStrings" in config.gJSONData) {
- this.commentStrings = config.gJSONData.commentStrings;
- }
-
- if ("constantData" in config.gJSONData) {
- // this is wrong, I shouldn't bother anybody with my Xorg data, and
- // I should load it from URL
- // var stuff = JSON.parse(self.data.load("chiIDsGroupings.json"));
- this.constantData = config.gJSONData.constantData;
- }
-
- if ("CCmaintainer" in config.gJSONData.constantData) {
- this.defBugzillaMaintainerArr = config.gJSONData.constantData.CCmaintainer;
- }
-
- if ("submitsLogging" in config.gJSONData.configData &&
- config.gJSONData.configData.submitsLogging) {
- this.log = config.logger;
- this.setUpLogging();
+
+ // Prepare for query buttons
+ // FIXME getting null for commentArea sometimes
+ var commentArea = this.doc.getElementById("comment_status_commit");
+ if (commentArea) {
+ var brElementPlacer = commentArea.getElementsByTagName("br");
+ console.log("brElementPlacer.length = " + brElementPlacer.length);
+ brElementPlacer = brElementPlacer[0];
+ if (brElementPlacer) {
+ brElementPlacer.setAttribute("id","brElementPlacer_location");
+ brElementPlacer.parentNode.insertBefore(this.doc.createElement("br"),
+ brElementPlacer);
+ }
+ } else {
+ console.log("Cannot find element with 'comment_status_commit' ID!");
}
this.generateButtons();
@@ -102,13 +94,16 @@ BZPage.prototype.getBugId = function getBugId () {
/**
*
*/
-BZPage.prototype.getInstalledPackages = function getInstalledPackages(config) {
+BZPage.prototype.getInstalledPackages = function getInstalledPackages(cfg) {
var installedPackages = {};
- if (config.gJSONData && ("commentPackages" in config.gJSONData)) {
- var enabledPackages = jetpack.storage.settings.enabledPacks.split(/[, ]/);
+
+ if (cfg.gJSONData && ("commentPackages" in cfg.gJSONData)) {
+ // TODO: Temporary hack ... should be replaced by a proper configuration
+ // when replacement for jetpack.storage.settings lands
+ var enabledPackages = cfg.gJSONData.configData.enabledPacks.split(/[, ]/);
enabledPackages.forEach(function (pkg, idx, arr) {
- if (pkg in config.gJSONData.commentPackages) {
- installedPackages[pkg] = config.gJSONData.commentPackages[pkg];
+ if (pkg in cfg.gJSONData.commentPackages) {
+ installedPackages[pkg] = cfg.gJSONData.commentPackages[pkg];
}
});
}
@@ -396,8 +391,12 @@ BZPage.prototype.generateButtons = function generateButtons () {
* @return string
*/
BZPage.prototype.getReporter = function getReporter () {
- return this.doc
- .querySelector("#bz_show_bug_column_2 > table .vcard:first-of-type > a").textContent;
+ var reporterElement = this.doc.
+ querySelector("#bz_show_bug_column_2 > table .vcard:first-of-type > a");
+ if (reporterElement) {
+ return reporterElement.textContent;
+ }
+ return "";
};
/**
@@ -628,36 +627,26 @@ BZPage.prototype.getAttachments = function getAttachments () {
* @return String with the password
*/
BZPage.prototype.getPassword = function getPassword () {
- if (jetpack.storage.settings.BZpassword) {
- return jetpack.storage.settings.BZpassword;
+ if (preferences.isSet("BZpassword")) {
+ return preferences.get("BZpassword",undefined);
} else {
- var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- var password = {
- value : ""
- }; // default the password to pass
- var check = {
- value : true
- }; // default the checkbox to true
- var result = prompts.promptPassword(null, "Title", "Enter password:",
- password, null, check);
- // result is true if OK was pressed, false if cancel was pressed.
- // password.value is
- // set if OK was pressed. The checkbox is not displayed.
- if (result) {
- var passwordText = password.value;
- jetpack.storage.settings.BZpassword = passwordText;
- jetpack.storage.simple.sync();
- return passwordText;
+ var passwordText = util.getPassword();
+ if (passwordText) {
+ preferences.set("BZpassword", passwordText);
}
}
- return null;
};
/**
*
*/
BZPage.prototype.setUpLogging = function setUpLogging () {
+ // Protection against double-call
+ if (this.doc.getElementById("generateTSButton")) {
+ console.log("Logging has been already set up!");
+ return ;
+ }
+
// For adding additional buttons to the top toolbar
var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions");
var that = this;
@@ -702,17 +691,11 @@ BZPage.prototype.setUpLogging = function setUpLogging () {
var clearLogAElem = this.doc.getElementById("clearLogs");
clearLogAElem.addEventListener("click", function() {
that.log.store = {};
- jetpack.storage.simple.sync();
this.style.color = that.log.EmptyLogsColor;
this.style.fontWeight = "normal";
console.log("this.store wiped out!");
}, false);
- if (!this.log.store) {
- console.log("No this.store defined!");
- this.log.store = {};
- }
-
if (this.log.store.length > 0) {
clearLogAElem.style.color = this.log.FullLogsColor;
clearLogAElem.style.fontWeight = "bolder";
diff --git a/lib/logger.js b/lib/logger.js
index ad7f4e9..3a534d4 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -4,6 +4,7 @@
var urlMod = require("url");
var urilMod = require("util");
var Color = require("color").Color;
+var tabs = require("tabs");
var Logger = exports.Logger = function Logger(store, abbsMap) {
this.EmptyLogsColor = new Color(0, 255, 0);
@@ -18,7 +19,7 @@ Logger.prototype.addLogRecord = function(that) {
rec.date = new Date();
rec.url = that.doc.location.toString();
rec.title = that.title;
- var comment = jetpack.tabs.focused.contentWindow.prompt(
+ var comment = tabs.activeTab.contentWindow.prompt(
"Enter comments for this comment");
if (comment && comment.length > 0) {
comment = comment.trim();
@@ -38,7 +39,6 @@ Logger.prototype.addLogRecord = function(that) {
} else {
this.store[recKey] = rec;
}
- jetpack.storage.simple.sync();
}
return comment;
};
@@ -98,13 +98,14 @@ Logger.prototype.createBlankPage = function (ttl, bodyBuildCB) {
var title = ttl || "Yet another untitled page";
var that = this;
- var logTab = jetpack.tabs.open("about:blank");
- jetpack.tabs.onReady(function() {
- var otherDoc = logTab.contentDocument;
- otherDoc.title = title;
- otherDoc.body.innerHTML = "<h1>" + title + "</h1>";
- bodyBuildCB.call(that, otherDoc.body);
- logTab.focus();
+ var logTab = tabs.open({
+ url: "about:blank",
+ onOpen: function (tab) {
+ var otherDoc = tab.contentDocument;
+ otherDoc.title = title;
+ otherDoc.body.innerHTML = "<h1>" + title + "</h1>";
+ bodyBuildCB.call(that, otherDoc.body);
+ }
});
};
diff --git a/lib/main.js b/lib/main.js
index f083b3f..04d89aa 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -1,5 +1,4 @@
/*jslint onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
-/*global jetpack */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
//
@@ -88,6 +87,11 @@ function initialize(callback) {
});
}
+ if (!myStorage.logs) {
+ console.log("myStorage.logs empty!");
+ myStorage.logs = {};
+ }
+
config.logger = new logger.Logger(myStorage.logs,
config.gJSONData.constantData.bugzillalabelAbbreviations);
diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js
index 5e27b4b..123f87e 100644
--- a/lib/rhbzpage.js
+++ b/lib/rhbzpage.js
@@ -1,5 +1,4 @@
/*jslint onevar: false, browser: true, evil: true, laxbreak: true, undef: true, nomen: true, eqeqeq: true, bitwise: true, maxerr: 1000, immed: false, white: false, plusplus: false, regexp: false, undef: false */
-/*global jetpack */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
"use strict";
@@ -11,6 +10,8 @@ var clip = require("clipboard");
var Color = require("color").Color;
var BZPage = require("bzpage").BZPage;
var url = require("url");
+var selection = require("selection");
+var tabs = require("tabs");
// var TriagedDistro = 13;
// var NumberOfFrames = 7;
// var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi";
@@ -65,20 +66,6 @@ var RHBugzillaPage = function RHBugzillaPage(doc, config) {
var ITbutton = this.doc.getElementById("cf_issuetracker");
this.its = ITbutton ? ITbutton.value.trim() : "";
- // Prepare for query buttons
- // FIXME getting null for commentArea sometimes
- var commentArea = this.doc.getElementById("comment_status_commit");
- if (commentArea) {
- var brElementPlacer = commentArea.getElementsByTagName("br");
- console.log("brElementPlacer.length = " + brElementPlacer.length);
- brElementPlacer = brElementPlacer[0];
- if (brElementPlacer) {
- brElementPlacer.setAttribute("id","brElementPlacer_location");
- brElementPlacer.parentNode.insertBefore(this.doc.createElement("br"),
- brElementPlacer);
- }
- }
-
// set default assignee on change of the component
this.doc.getElementById("component").addEventListener("change",
function() {
@@ -177,8 +164,8 @@ RHBugzillaPage.prototype.closeSomeRelease = function() {
var text = "";
var resolution = "";
- if (jetpack.selection.text) {
- text = jetpack.select.text.trim();
+ if (selection.text) {
+ text = selection.text.trim();
}
if (text.length > 0) {
resolution = "CURRENTRELEASE";
@@ -406,9 +393,8 @@ RHBugzillaPage.prototype.setBranding = function() {
// mark suspicious components
var compElems;
- var suspiciousComponents = config.gJSONData.configData.suspiciousComponents;
- if (suspiciousComponents
- && util.isInList(this.component, suspiciousComponents)
+ if (this.suspiciousComponents
+ && util.isInList(this.component, this.suspiciousComponents)
&& (compElems = this.doc
.getElementById("bz_component_edit_container"))) {
compElems.style.background = "red none";
@@ -546,6 +532,17 @@ RHBugzillaPage.prototype.fillInChipMagic = function () {
this.XorgLogAttListIndex++;
};
+RHBugzillaPage.prototype.getSelectionOrClipboard = function getSelectionOrClipboard () {
+ var text = selection.text;
+ console.log("selection = " + text);
+ if (!text) {
+ text = clip.get();
+ console.log("clipboard = " + text);
+ }
+ console.log("text = " + text);
+ return text;
+};
+
/**
* Opens a new tab with a query for the given text in the selected component
*
@@ -560,12 +557,12 @@ RHBugzillaPage.prototype.queryInNewTab = function(text, component, product) {
console.log("queryInNewTab / text = " + text);
console.log("queryInNewTab / component = " + component);
console.log("queryInNewTab / product = " + product);
- var url = "https://bugzilla.redhat.com/buglist.cgi?query_format=advanced";
+ var urlStr = "https://bugzilla.redhat.com/buglist.cgi?query_format=advanced";
if (product) {
- url += "&product=" + product.trim();
+ urlStr += "&product=" + product.trim();
}
if (component) {
- url += "&field0-0-0=component&type0-0-0=substring&value0-0-0="
+ urlStr += "&field0-0-0=component&type0-0-0=substring&value0-0-0="
+ component.trim();
}
// using more complicated query tables here, because they can be more easily
@@ -579,18 +576,8 @@ RHBugzillaPage.prototype.queryInNewTab = function(text, component, product) {
+ text
+ "&field1-0-2=status_whiteboard&type1-0-2=substring&value1-0-2="
+ text;
- url += searchText;
- jetpack.tabs.open(url);
- // Don't do it ... b.m.o is apparently not powerful enough to sustain
- // the weight
- // of the search
- if (false) {
- url = "https://bugzilla.mozilla.org/buglist.cgi?query_format=advanced"
- + "field0-0-0=product;type0-0-0=regexp;"
- + "value0-0-0=thunderbird|firefox|xulrunner"
- + searchText.replace("&", ";");
- jetpack.tabs.open(url);
- }
+ urlStr += searchText;
+ tabs.open({url: urlStr});
}
};
@@ -599,13 +586,7 @@ RHBugzillaPage.prototype.queryInNewTab = function(text, component, product) {
* function this.queryInNewTab, and run it.
*/
RHBugzillaPage.prototype.queryForSelection = function() {
- var text = jetpack.selection.text;
- console.log("selection = " + text);
- if (!text) {
- text = clip.get();
- console.log("clipboard = " + text);
- }
- console.log("text = " + text);
+ var text = this.getSelectionOrClipboard();
if (text) {
this.queryInNewTab(text, this.component);
}
@@ -616,16 +597,18 @@ RHBugzillaPage.prototype.queryForSelection = function() {
*/
RHBugzillaPage.prototype.queryUpstream = function() {
console.log("Querying upstream!");
- var text = jetpack.selection.text;
- console.log("Selection = |" + text + "|");
- if (!text) {
- text = clip.get();
- }
+ var text = this.getSelectionOrClipboard();
if (text) {
text = encodeURIComponent(text.trim());
var queryUpstreamBugsURLArray = this.constantData.queryUpstreamBug;
- var url = util.filterByRegexp(queryUpstreamBugsURLArray, this.component);
- jetpack.tabs.open(url + text);
+ var urlBase = util.filterByRegexp(queryUpstreamBugsURLArray, this.component);
+ tabs.open({
+ url: urlBase + text,
+ inBackground: true,
+ onOpen: function (t) {
+ t.activate();
+ }
+ });
}
};
@@ -633,19 +616,22 @@ RHBugzillaPage.prototype.queryUpstream = function() {
*
*/
RHBugzillaPage.prototype.sendBugUpstream = function() {
- var url = util.filterByRegexp(this.constantData.newUpstreamBug, this
+ var that = this;
+ var urlStr = util.filterByRegexp(this.constantData.newUpstreamBug, this
.getOptionValue("component"));
- var ret = jetpack.tabs.open(url);
- var that = this;
- jetpack.tabs.onReady(function() {
- var otherDoc = ret.contentDocument;
- var otherElems = otherDoc.forms.namedItem("Create").elements;
- otherElems.namedItem("short_desc").value = that.doc
- .getElementById("short_desc_nonedit_display").textContent
- .trim();
- otherElems.namedItem("comment").value = that.collectComments();
- ret.focus();
+ var ret = tabs.open({
+ url: urlStr,
+ inBackground: true,
+ onOpen: function (tab) {
+ var otherDoc = tab.contentDocument;
+ var otherElems = otherDoc.forms.namedItem("Create").elements;
+ otherElems.namedItem("short_desc").value = that.doc
+ .getElementById("short_desc_nonedit_display").textContent
+ .trim();
+ otherElems.namedItem("comment").value = that.collectComments();
+ ret.focus();
+ }
});
};
diff --git a/lib/util.js b/lib/util.js
index e14fcb1..7fca362 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -1,4 +1,4 @@
-/*global exports: false, require: false */
+/*global exports: false, require: false, Cc: false, Ci: false */
/*jslint onevar: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
@@ -49,6 +49,140 @@ var getBugNo = exports.getBugNo = function getBugNo(url) {
};
/**
+ * 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());
+};
+
+/**
+ * Make sure value returned is Array
+ *
+ * @param Array/String
+ * @return Array
+ *
+ * If something else than Array or String is passed to the function
+ * the result will be untouched actual argument of the call.
+ */
+var valToArray = exports.valToArray = function valToArray(val) {
+ var isArr = val &&
+ val.constructor &&
+ val.constructor.name === "Array";
+ return isArr ? val : [val];
+};
+
+/**
+ * Merges two comma separated string as a list and returns new string
+ *
+ * @param str String with old values
+ * @param value String/Array with other values
+ * @return String with merged lists
+ */
+exports.addCSVValue = function addCSVValue(str, value) {
+ var parts = (str.trim().length > 0 ? str.split(/,\s*/) : []);
+ if (!value) {
+ return str;
+ }
+ if (!isInList(value, parts)) {
+ var newValue = valToArray(value);
+ parts = parts.concat(newValue);
+ }
+ // this is necessary to get comma-space separated string even when
+ // value is an array already
+ parts = parts.join(",").split(",");
+ return parts.join(", ");
+};
+
+/**
+ * Treats comma separated string as a list and removes one item from it
+ *
+ * @param str String treated as a list
+ * @param value String with the value to be removed from str
+ * @return String with the resulting list comma separated
+ */
+exports.removeCSVValue = function removeCSVValue(str, value) {
+ str = str.trim();
+ var parts = str ? str.split(/,\s*/) : [];
+ var valueArr = value instanceof Array ? value : value.split(/,\s*/);
+ parts = parts.filter(function (e, i, a) {
+ return (!isInList(e, valueArr));
+ });
+ return parts.join(", ");
+};
+
+/**
+ * select element of the array where regexp in the first element matches second
+ * parameter of this function
+ *
+ * @param list Array with regexps and return values
+ * @param chosingMark String by which the element of array is to be matched
+ * @return Object chosen element
+ */
+var filterByRegexp = exports.filterByRegexp =
+ function filterByRegexp(list, chosingMark) {
+ let chosenPair = [];
+ if (list.length > 0) {
+ chosenPair = list.filter(function(pair) {
+ return new RegExp(pair.regexp, "i").test(chosingMark);
+ });
+ }
+ if (chosenPair.length > 0) {
+ return chosenPair[0].addr;
+ } else {
+ return "";
+ }
+};
+
+/**
+ * Check whether an item is member of the list. Idea is just to make long if
+ * commands slightly more readable.
+ *
+ * @param mbr string to be searched in the list
+ * @param list list
+ * @return position of the string in the list, or -1 if none found.
+ */
+var isInList = exports.isInList = function isInList(mbr, list) {
+ if (!list) {
+ return false;
+ }
+ return (list.indexOf(mbr) !== -1);
+};
+
+/**
+ * returns password with a special password
+ *
+ * @return String with the password
+ */
+var getPassword = exports.getPassword = function getPassword() {
+ var prompts = Cc["@mozilla.org/embedcomp/prompt-service;1"]
+ .getService(Ci.nsIPromptService);
+ var password = {
+ value : ""
+ }; // default the password to pass
+ var check = {
+ value : true
+ }; // default the checkbox to true
+ var result = prompts.promptPassword(null, "Title", "Enter password:",
+ password, null, check);
+ // result is true if OK was pressed, false if cancel was pressed.
+ // password.value is set if OK was pressed.
+ // The checkbox is not displayed.
+ if (result) {
+ return password.value ? password.value : null;
+ } else {
+ return undefined;
+ }
+};
+
+/**
* Load text from URL
*
* @param URL String