aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-06-21 17:44:25 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-06-21 17:44:25 +0200
commitb5da15622a8ee84cac5c8489c72610bd24b09c29 (patch)
treeea39f899db898780e05b5d2fe7f4cc55e09ba754 /lib
parenta0756d1dbd9e8bbb37293b8b756f6aee1e205d65 (diff)
downloadbugzilla-triage-b5da15622a8ee84cac5c8489c72610bd24b09c29.tar.gz
Skipping over process pages && system notification.
Diffstat (limited to 'lib')
-rw-r--r--lib/bzpage.js3
-rw-r--r--lib/logger.js12
-rw-r--r--lib/main.js56
-rw-r--r--lib/util.js69
4 files changed, 100 insertions, 40 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 5344fbb..616e78d 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -50,7 +50,8 @@ var BZPage = function BZPage(doc, config) {
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
this.log = config.logger;
- console.log("this.log = " + this.log.toSource());
+ console.log("length of this.log.store = " +
+ this.log.getLength());
this.setUpLogging();
}
diff --git a/lib/logger.js b/lib/logger.js
index 594f5c2..0f7de76 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -11,9 +11,7 @@ function Logger(store, abbsMap) {
this.EmptyLogsColor = new Color(0, 255, 0);
this.FullLogsColor = new Color(0, 40, 103);
- console.log("store = " + store.toSource());
this.store = store;
- console.log("abbsMap = " + abbsMap.toSource());
this.abbsMap = abbsMap;
};
@@ -44,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 {
@@ -55,6 +51,14 @@ Logger.prototype.addLogRecord = function(that) {
return comment;
};
+Logger.prototype.getLength = function () {
+ var counter = 0;
+ for (var key in this.store) {
+ counter += 1;
+ }
+ return counter;
+}
+
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 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