aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/logger.js2
-rw-r--r--lib/main.js56
-rw-r--r--lib/util.js69
3 files changed, 90 insertions, 37 deletions
diff --git a/lib/logger.js b/lib/logger.js
index 88a3215..0f7de76 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -42,8 +42,6 @@ Logger.prototype.addLogRecord = function(that) {
console.log("recKey = " + recKey);
console.log("rec = " + rec.toSource());
- console.log("this.store = " + this.store);
-
if (this.store[recKey]) {
this.store[recKey].comment += "<br/>\n" + comment;
} else {
diff --git a/lib/main.js b/lib/main.js
index 867c3d5..7c72599 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -15,6 +15,7 @@ var util = require("util");
var logger = require("logger");
var myStorage = require("simple-storage").storage;
var browser = require("tab-browser");
+var urlMod = require("url");
var JSONURL = "http://matej.ceplovi.cz/progs/data/RH_Data-packages.json";
var TriagedDistro = 13;
@@ -27,6 +28,12 @@ config.matches = [
"https://bugzilla.mozilla.org/show_bug.cgi"
];
+config.skipMatches = [
+ "https://bugzilla.redhat.com/process_bug.cgi",
+ "https://bugzilla.redhat.com/post_bug.cgi",
+ "https://bugzilla.mozilla.org/post_bug.cgi",
+ "https://bugzilla.mozilla.org/process_bug.cgi"
+];
// ==============================================================
// https://wiki.mozilla.org/Labs/Jetpack/JEP/24
@@ -52,16 +59,7 @@ var WillBemanifest = {
]
};
-// TODO: sometime in the future we should include
-// also skip-process.js functionality and these URLs
-// "https://bugzilla.redhat.com/process_bug.cgi",
-// "https://bugzilla.redhat.com/post_bug.cgi",
-// "https://bugzilla.mozilla.org/post_bug.cgi",
-// "https://bugzilla.mozilla.org/process_bug.cgi"
function isOurPage(window, matchingURLs) {
- if ("window" in window) {
- window = window.window;
- }
var url = window.location.href;
// like ["regexp-url1", "regexp-url2"]
@@ -70,6 +68,25 @@ function isOurPage(window, matchingURLs) {
});
}
+/**
+ *
+ */
+function skipThisPage(doc) {
+ var stemURL = "https://HOSTNAME/show_bug.cgi?id=";
+ var titleStr = doc.getElementsByTagName("title")[0].textContent;
+ var REArr = new RegExp("[0-9]+").exec(titleStr);
+ var hostname = urlMod.URL(doc.location.href).host;
+ if (REArr) {
+ var bugNo = REArr[0];
+ console.log("bugNo = " + bugNo + ", hostname = " + hostname);
+ var emailsSent = doc.
+ querySelector("#bugzilla-body > dl:nth-of-type(1)").textContent;
+ emailsSent = emailsSent.replace(/^(\s*)$/mg,"");
+ util.notification(emailsSent);
+ doc.location = stemURL.replace("HOSTNAME",hostname) + bugNo;
+ }
+}
+
function initialize(callback) {
util.loadJSON(JSONURL, function(parsedData) {
config.gJSONData = parsedData;
@@ -103,14 +120,19 @@ function initialize(callback) {
exports.main = function main(options, callbacks) {
initialize(function (config) {
browser.whenContentLoaded(
- function(window) {
- var doc = window.document;
- var construct = require("rhbzpage").RHBugzillaPage;
- if (isOurPage(window, config.matches)) {
- var curPage = new construct(doc, config);
- } else {
- console.log("Not our page: " + window.location.href);
+ function(window) {
+ // is this good for anything?
+ if ("window" in window) { window = window.window; }
+ var doc = window.document;
+ var construct = require("rhbzpage").RHBugzillaPage;
+ if (isOurPage(window, config.matches)) {
+ var curPage = new construct(doc, config);
+ } else if (isOurPage(window, config.skipMatches)) {
+ skipThisPage(doc);
+ } else {
+ console.log("Not our page: " + window.location.href);
+ }
}
- });
+ );
});
};
diff --git a/lib/util.js b/lib/util.js
index 4cb158a..b832ac0 100644
--- a/lib/util.js
+++ b/lib/util.js
@@ -1,4 +1,4 @@
-/*global exports: false, require: false, Cc: false, Ci: false */
+/*global exports: false, require: false, Cc: false, Ci: false, console: false */
/*jslint onevar: false */
// Released under the MIT/X11 license
// http://www.opensource.org/licenses/mit-license.php
@@ -49,6 +49,39 @@ exports.getBugNo = function getBugNo(url) {
};
/**
+ * Show a system notification with the given message
+ *
+ * @param String or Object with a message to be shown in a default
+ * notification or object with properties title, icon, and body
+ * @return None
+ */
+exports.notification = function notification(msg) {
+ var body = msg;
+ var title = "Bugzilla Notification";
+ var icon = null;
+
+ if (typeof(msg) === "object") {
+ body = msg.body;
+ }
+ if ("title" in msg) {
+ title = msg.title;
+ }
+ if ("icon" in msg) {
+ icon = msg.icon;
+ }
+ try {
+ var classObj = Cc["@mozilla.org/alerts-service;1"];
+ var alertService = classObj.getService(Ci.nsIAlertsService);
+
+ alertService.showAlertNotification(icon, title, body);
+ return true;
+ } catch (e) {
+ console.error("Unable to display notification:", msg);
+ return false;
+ }
+};
+
+/**
* format date to be in ISO format (just day part)
*
* @param date
@@ -64,6 +97,21 @@ exports.getISODate = function getISODate(dateStr) {
};
/**
+ * 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);
+};
+
+/**
* Make sure value returned is Array
*
* @param Array/String
@@ -128,9 +176,9 @@ exports.removeCSVValue = function removeCSVValue(str, value) {
*/
var filterByRegexp = exports.filterByRegexp =
function filterByRegexp(list, chosingMark) {
- let chosenPair = [];
+ var chosenPair = [];
if (list.length > 0) {
- chosenPair = list.filter(function(pair) {
+ chosenPair = list.filter(function (pair) {
return new RegExp(pair.regexp, "i").test(chosingMark);
});
}
@@ -142,21 +190,6 @@ var filterByRegexp = exports.filterByRegexp =
};
/**
- * 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