aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2010-05-24 15:02:59 +0200
committerMatěj Cepl <mcepl@redhat.com>2010-05-24 15:02:59 +0200
commit0dcce743668fb6e794e21cddef731a9401f81d11 (patch)
tree3e295bb72c10697fcc296700d1dacc45592bf349
parentd6776e719324d1a883a99ff9fb631c838a682ca2 (diff)
downloadbugzilla-triage-0dcce743668fb6e794e21cddef731a9401f81d11.tar.gz
The first version of Logger object.
-rw-r--r--RH_Data-packages.json10
-rw-r--r--bugzillaBugTriage.js311
2 files changed, 184 insertions, 137 deletions
diff --git a/RH_Data-packages.json b/RH_Data-packages.json
index 840b5d9..e1f3dc3 100644
--- a/RH_Data-packages.json
+++ b/RH_Data-packages.json
@@ -219,7 +219,15 @@
"bugzilla.mozilla.org": "Mozilla Foundation",
"bugs.freedesktop.org": "FreeDesktop.org",
"bugs.eclipse.org": "Eclipse Project",
- "bugzilla.gnome.org": "GNOME Desktop"
+ "bugzilla.gnome.org": "GNOME Desktop",
+ "bugzilla.redhat.com": "Red Hat"
+ },
+ "bugzillalabelAbbreviations": {
+ "bugzilla.mozilla.org": "MoFo",
+ "bugs.freedesktop.org": "FDo",
+ "bugs.eclipse.org": "Eclipse",
+ "bugzilla.gnome.org": "bgo",
+ "bugzilla.redhat.com": "RH"
},
"bugzillaIDURLs": [
null,
diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js
index 2397445..d57adf7 100644
--- a/bugzillaBugTriage.js
+++ b/bugzillaBugTriage.js
@@ -261,6 +261,21 @@ hlpr.isInList = function(mbr, list) {
};
/**
+ * format date to be in ISO format (just day part)
+ *
+ * @param date
+ * @return string with the formatted date
+ */
+hlpr.getISODate = function (dateStr) {
+ function pad(n) {
+ return n < 10 ? '0' + n : n;
+ }
+ let date = new Date(dateStr);
+ return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-'
+ + pad(date.getDate());
+};
+
+/**
* Make sure value returned is Array
*
* @param Array/String
@@ -312,6 +327,37 @@ hlpr.removeCSVValue = function removeCSVValue(str, value) {
};
/**
+ * From given URL returns hostname of the server
+ *
+ * @param url String with the investigated URL
+ * @return String with hostname
+ */
+hlpr.getHost = function(url) {
+ let aElem = jetpack.tabs.focused.contentWindow.document.createElement("a");
+ aElem.setAttribute("href",url);
+ return aElem.hostname;
+}
+
+/**
+ *
+ */
+hlpr.getBugNo = function(url) {
+ // FIXME Why not to parse URL?
+// let bugNoTitle = this.doc.querySelector("#title > p").textContent.trim();
+// console.log("bugNoTitle = " + bugNoTitle);
+// this.bugNo = this.getBugNo(this.doc.location.toString());
+// https://bugzilla.redhat.com/show_bug.cgi?id=583826
+ let re = new RegExp(".*id=([0-9]+).*$");
+ let bugNo = null;
+ let reResult = re.exec(url);
+ if (reResult[1]) {
+ bugNo = reResult[1];
+ console.log("this.bugNo = " + bugNo);
+ }
+ return bugNo;
+};
+
+/**
* Load text from URL
*
* @param URL String
@@ -595,6 +641,97 @@ Color.prototype.lightColor = function() {
};
// ====================================================================================
+// Logger
+
+function Logger(store, abbsMap) {
+ this.EmptyLogsColor = new Color(0, 255, 0);
+ this.FullLogsColor = new Color(0, 40, 103);
+
+ this.store = store;
+ this.abbsMap = abbsMap;
+};
+
+// FIXME we should store whole URL, not just ID (to cooperate with other bugzillas)
+// General rule: there is nothing special about bugzilla.redhat.com, so for example
+// constantData.bugzillalabelNames should be made non-RH-centric
+// and getBugzillaName should work everywhere same (even on bugzilla.mozilla.org,
+// if that makes sense?)
+Logger.prototype.addLogRecord = function(that) {
+ let rec = {};
+ rec.date = new Date();
+ rec.url = that.doc.location.toString();
+ rec.title = that.title;
+ let comment = jetpack.tabs.focused.contentWindow.prompt(
+ "Enter comments for this comment").trim();
+ if (comment.length > 0) {
+ rec.comment = comment;
+ let recKey = hlpr.getISODate(rec.date) + "+" + hlpr.getHost(rec.url)
+ + "+" + that.bugNo;
+ let clearLogAElem = that.doc.getElementById("clearLogs");
+ clearLogAElem.style.color = this.FullLogsColor;
+ clearLogAElem.style.fontWeight = "bolder";
+ if (this.store[recKey]) {
+ this.store[recKey].comment += "<br/>\n" + comment;
+ } else {
+ this.store[recKey] = rec;
+ }
+ jetpack.storage.simple.sync();
+ return rec;
+ } else if (comment === null) {
+ return null;
+ }
+};
+
+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
+ var abbr = this.abbsMap[host];
+ console.log("abbr = " + abbr);
+ return abbr;
+}
+
+Logger.prototype.timeSheetRecordsPrinter = function(body, records) {
+ let that = this;
+ // sort the records into temporary array
+ let tmpArr = [];
+
+ for ( let i in records) {
+ if (records.hasOwnProperty(i)) {
+ tmpArr.push( [ i, records[i] ]);
+ }
+ }
+ tmpArr.sort(function(a, b) {
+ return a[0] > b[0] ? 1 : -1;
+ });
+
+ let currentDay = "";
+ // now print the array
+ tmpArr.forEach(function(rec) {
+ let x = rec[1];
+ let dayStr = hlpr.getISODate(x.date);
+ let BZName = that.getBugzillaAbbr(x.url);
+ let bugNo = hlpr.getBugNo(x.url);
+ if (dayStr != currentDay) {
+ currentDay = dayStr;
+ body.innerHTML += "<hr/><p><strong>" + currentDay
+ + "</strong></p>";
+ }
+ body.innerHTML += "<p><em><a href='"
+ + x.url
+ + "'>Bug "
+ + BZName + "/" + bugNo + ": "
+ + x.title
+ + "</a>"
+ + " </em>\n<br/>" + x.comment + "</p>";
+ });
+};
+
+Logger.prototype.generateTimeSheet = function(body) {
+ let doc = body.ownerDocument;
+ this.timeSheetRecordsPrinter(body, this.store);
+};
+
+// ====================================================================================
// BZPage's methods
function BZPage(doc) {
@@ -602,10 +739,7 @@ function BZPage(doc) {
this.SalmonPink = new Color(255, 224, 176); // RGB 255, 224, 176; HSL 36, 2,
// 85
this.ReporterColor = new Color(255, 255, 166); // RGB 255, 255, 166; HSL 60, 2,
- // 83
- this.EmptyLogsColor = new Color(0, 255, 0);
- this.FullLogsColor = new Color(0, 40, 103);
-
+ // 83
this.RE = {
Comment: new RegExp("^\\s*#"), // unsused
BlankLine: new RegExp("^\\s*$"), // unused
@@ -620,13 +754,13 @@ function BZPage(doc) {
};
-
// initialize dynamic properties
this.doc = doc;
this.packages = this.getInstalledPackages();
if ("commentStrings" in config.gJSONData) {
this.commentStrings = config.gJSONData.commentStrings;
}
+
if ("constantData" in config.gJSONData) {
this.constantData = config.gJSONData.constantData;
}
@@ -637,10 +771,11 @@ function BZPage(doc) {
if ("submitsLogging" in config.gJSONData.configData &&
config.gJSONData.configData.submitsLogging) {
- this.setUpLoggingButtons();
+ this.log = config.logger;
+ this.setUpLogging();
}
-
- this.bugNo = this.getBugNo(this.doc.location.toString());
+
+ this.bugNo = hlpr.getBugNo(this.doc.location.toString());
this.reporter = this.getReporter();
this.product = this.getOptionValue("product");
this.component = this.getOptionValue("component");
@@ -956,22 +1091,6 @@ BZPage.prototype.generateButtons = function() {
}
};
-BZPage.prototype.getBugNo = function(url) {
- // FIXME Why not to parse URL?
-// let bugNoTitle = this.doc.querySelector("#title > p").textContent.trim();
-// console.log("bugNoTitle = " + bugNoTitle);
-// this.bugNo = this.getBugNo(this.doc.location.toString());
-// https://bugzilla.redhat.com/show_bug.cgi?id=583826
- let re = new RegExp(".*id=([0-9]+).*$");
- let bugNo = null;
- let reResult = re.exec(url);
- if (reResult[1]) {
- bugNo = reResult[1];
- console.log("this.bugNo = " + bugNo);
- }
- return bugNo;
-};
-
/**
* Get the current email of the reporter of the bug.
*
@@ -1067,21 +1186,6 @@ BZPage.prototype.clickMouse = function(targetID) {
};
/**
- * format date to be in ISO format (just day part)
- *
- * @param date
- * @return string with the formatted date
- */
-BZPage.prototype.getISODate = function (dateStr) {
- function pad(n) {
- return n < 10 ? '0' + n : n;
- }
- let date = new Date(dateStr);
- return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-'
- + pad(date.getDate());
-};
-
-/**
* select element of the array where regexp in the first element matches second
* parameter of this function
*
@@ -1283,8 +1387,8 @@ BZPage.prototype.getPassword = function() {
/**
*
*/
-BZPage.prototype.setUpLoggingButtons = function() {
- console.log("LOgging setUpLoggingButtons");
+BZPage.prototype.setUpLogging = function() {
+ console.log("Logging setUpLogging");
// For adding additional buttons to the top toolbar
let additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions");
let that = this;
@@ -1292,7 +1396,7 @@ BZPage.prototype.setUpLoggingButtons = function() {
// logging all submits for timesheet
this.doc.forms.namedItem("changeform").addEventListener("submit",
function(evt) {
- if (that.addLogRecord() === null) {
+ if (that.log.addLogRecord(that) == null) {
// FIXME doesn't work ... still submitting'
evt.stopPropagation();
evt.preventDefault();
@@ -1318,23 +1422,23 @@ BZPage.prototype.setUpLoggingButtons = function() {
additionalButtons.appendChild(clearLogsUI);
let clearLogAElem = this.doc.getElementById("clearLogs");
clearLogAElem.addEventListener("click", function() {
- myStorage.logs = {};
+ that.log.store = {};
jetpack.storage.simple.sync();
- this.style.color = that.EmptyLogsColor;
- clearLogAElem.style.fontWeight = "normal";
- console.log("mystorage.logs wiped out!");
+ this.style.color = that.log.EmptyLogsColor;
+ this.style.fontWeight = "normal";
+ console.log("this.store wiped out!");
}, false);
- if (!myStorage.logs) {
- console.log("No myStorage.logs defined!");
- myStorage.logs = {};
+ if (!this.store) {
+ console.log("No this.store defined!");
+ this.store = {};
}
- if (myStorage.logs) {
- clearLogAElem.style.color = this.FullLogsColor;
+ if (this.log.store.length > 0) {
+ clearLogAElem.style.color = this.log.FullLogsColor;
clearLogAElem.style.fontWeight = "bolder";
} else {
- clearLogAElem.style.color = this.EmptyLogsColor;
+ clearLogAElem.style.color = this.log.EmptyLogsColor;
clearLogAElem.style.fontWeight = "normal";
}
};
@@ -1409,10 +1513,12 @@ RHBugzillaPage = function(doc) {
// Prepare for query buttons
// FIXME getting null for commentArea sometimes
let commentArea = doc.getElementById("comment_status_commit");
- let brElementPlacer = commentArea.getElementsByTagName("br")[0];
- brElementPlacer.setAttribute("id","brElementPlacer_location");
- brElementPlacer.parentNode.insertBefore(doc.createElement("br"),
- brElementPlacer);
+ if (commentArea) {
+ let brElementPlacer = commentArea.getElementsByTagName("br")[0];
+ brElementPlacer.setAttribute("id","brElementPlacer_location");
+ brElementPlacer.parentNode.insertBefore(doc.createElement("br"),
+ brElementPlacer);
+ }
// inheritance ... call superobject's constructor
BZPage.call(this,doc);
@@ -1482,10 +1588,6 @@ RHBugzillaPage = function(doc) {
this.fillInChipMagic();
}
}
-
- if (logSubmits) {
- this.setUpLoggingButtons();
- }
} // END OF RHBugzillaPage CONSTRUCTOR
RHBugzillaPage.prototype = hlpr.heir(BZPage);
@@ -2504,84 +2606,9 @@ RHBugzillaPage.prototype.parseBacktrace = function(ret) {
return outStr;
};
-// FIXME we should store whole URL, not just ID (to cooperate with other bugzillas)
-// General rule: there is nothing special about bugzilla.redhat.com, so for example
-// constantData.bugzillalabelNames should be made non-RH-centric
-// and getBugzillaName should work everywhere same (even on bugzilla.mozilla.org,
-// if that makes sense?)
-RHBugzillaPage.prototype.addLogRecord = function() {
- let rec = {};
- rec.date = new Date();
- rec.url = this.doc.location.toString();
- rec.title = this.title;
- let comment = jetpack.tabs.focused.contentWindow.prompt(
- "Enter comments for this comment").trim();
- if (comment.length > 0) {
- rec.comment = comment;
- let recKey = this.getISODate(rec.date) + "+" + rec.bugId;
- let clearLogAElem = this.doc.getElementById("clearLogs");
- clearLogAElem.style.color = this.FullLogsColor;
- clearLogAElem.style.fontWeight = "bolder";
- if (myStorage.logs[recKey]) {
- myStorage.logs[recKey].comment += "<br/>\n" + comment;
- } else {
- myStorage.logs[recKey] = rec;
- }
- jetpack.storage.simple.sync();
- } else if (comment === null) {
- return null;
- }
-};
-
-RHBugzillaPage.prototype.timeSheetRecordsPrinter = function(body, records) {
- let that = this;
- // sort the records into temporary array
- let tmpArr = [];
-
- for ( let i in records) {
- if (records.hasOwnProperty(i)) {
- tmpArr.push( [ i, records[i] ]);
- }
- }
- tmpArr.sort(function(a, b) {
- return a[0] > b[0] ? 1 : -1;
- });
-
- let currentDay = "";
- // now print the array
- tmpArr
- .forEach(function(rec) {
- let x = rec[1];
- let dayStr = that.getISODate(x.date);
- if (dayStr != currentDay) {
- currentDay = dayStr;
- body.innerHTML += "<hr/><p><strong>" + currentDay
- + "</strong></p>";
- }
- body.innerHTML += "<p><em><a href='https://bugzilla.redhat.com/show_bug.cgi?id="
- + x.bugId
- + "'>Bug "
- + x.title
- + "</a>"
- + " </em>\n<br/>" + x.comment + "</p>";
- });
-};
-
-RHBugzillaPage.prototype.generateTimeSheet = function(body) {
- let doc = body.ownerDocument;
- this.timeSheetRecordsPrinter(body, myStorage.logs);
-};
// /////////////////////////////////////////////////////////////////////////////
-let callback = function(doc) {
- if (config.gJSONData.configData.objectStyle = "RH") {
- let curPage = new RHBugzillaPage(doc);
- } else if (config.gJSONData.configData.objectStyle = "MoFo") {
- let curPage = new MozillaBugzilla(doc);
- }
-};
-
let config = {};
config.matches = [
"https://bugzilla.redhat.com/show_bug.cgi",
@@ -2603,5 +2630,17 @@ hlpr.loadJSON(jetpack.storage.settings.JSONURL, function(parsedData) {
config.PCI_ID_Array = response;
});
}
+
+ config.logger = new Logger(myStorage.logs,
+ config.gJSONData.constantData.bugzillalabelAbbreviations);
+
+ let callback = function(doc) {
+ if (config.gJSONData.configData.objectStyle = "RH") {
+ let curPage = new RHBugzillaPage(doc);
+ } else if (config.gJSONData.configData.objectStyle = "MoFo") {
+ let curPage = new MozillaBugzilla(doc);
+ }
+ };
+
+ jetpack.pageMods.add(callback, config);
}, this);
-jetpack.pageMods.add(callback, config);