From b5da15622a8ee84cac5c8489c72610bd24b09c29 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Mon, 21 Jun 2010 17:44:25 +0200 Subject: Skipping over process pages && system notification. --- lib/bzpage.js | 3 ++- lib/logger.js | 12 +++++++---- lib/main.js | 56 +++++++++++++++++++++++++++++++++--------------- lib/util.js | 69 +++++++++++++++++++++++++++++++++++++++++++---------------- 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 += "
\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 @@ -48,6 +48,39 @@ exports.getBugNo = function getBugNo(url) { return bugNo; }; +/** + * 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) * @@ -63,6 +96,21 @@ exports.getISODate = function getISODate(dateStr) { pad(date.getDate()); }; +/** + * 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 * @@ -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); }); } @@ -141,21 +189,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 * -- cgit