aboutsummaryrefslogtreecommitdiffstats
path: root/data/lib
diff options
context:
space:
mode:
Diffstat (limited to 'data/lib')
-rw-r--r--data/lib/bugzillaDOMFunctions.js47
-rw-r--r--data/lib/bzpage.js45
-rw-r--r--data/lib/collectingMetadata.js188
-rw-r--r--data/lib/otherButtons.js31
-rw-r--r--data/lib/util.js33
5 files changed, 285 insertions, 59 deletions
diff --git a/data/lib/bugzillaDOMFunctions.js b/data/lib/bugzillaDOMFunctions.js
index 8f74288..aedf131 100644
--- a/data/lib/bugzillaDOMFunctions.js
+++ b/data/lib/bugzillaDOMFunctions.js
@@ -147,6 +147,32 @@ function getDefaultBugzillaMaintainer (component) {
}
/**
+ * dd
+ *
+ * @return Element with the href attribute containng the information
+ */
+function getOptionTableCell(tableId, label) {
+ var cleanLabelRE = new RegExp("^\\s*([^.:]*):?\\s*$");
+ label = label.trim().replace(cleanLabelRE,"$1").toLowerCase();
+
+ var rows = document.getElementById(tableId).getElementsByTagName("tr");
+ var ourLine = Array.filter(rows, function(row) {
+ var curLabelElems = row.getElementsByTagName("td");
+ if (curLabelElems.length > 0) {
+ var curLabel = curLabelElems[0].textContent.toLowerCase();
+ curLabel = curLabel.replace(cleanLabelRE,"$1");
+ return (curLabel === label); // maybe this could be a RE match instead
+ }
+ });
+
+ if (ourLine.length > 0) {
+ return ourLine[0].getElementsByTagName("td")[1].
+ getElementsByTagName("a")[0];
+ }
+ return null;
+}
+
+/**
* Generic function to add new button to the page. Actually copies new button
* from the old one (in order to have the same look-and-feel, etc.
*
@@ -408,7 +434,6 @@ function killNodes(doc, target, remove) {
// removing its members.
for(var i = 0, ii = victimElements.length; i < ii; i++) {
elem = victimElements[i];
- console.myDebug("Killing element " + elem[0]);
try {
elem[1].parentNode.removeChild(elem[1]);
}
@@ -456,3 +481,23 @@ function getBugzillaName(URLhostname, bzLabelNames) {
}
return bugzillaID;
}
+
+/**
+ *
+ * original 2011-03-30 15:49:27 EDT
+ */
+function parseBZCommentDate(dateString) {
+ var tZone = {
+ "EDT": 4,
+ "EST": 5
+ };
+
+ var dateArr = dateString.trim().split(/\s+/);
+ var timeZoneOffset = tZone[dateArr[2]] -
+ ((new Date()).getTimezoneOffset())/60;
+ var dArr = dateArr[0].split("-");
+ var tArr = dateArr[1].split(":");
+ var dayObj = new Date(+dArr[0],+dArr[1]-1,+dArr[2],
+ +tArr[0]+timeZoneOffset,+tArr[1],+tArr[2],0);
+ return dayObj;
+};
diff --git a/data/lib/bzpage.js b/data/lib/bzpage.js
index c1898eb..4401792 100644
--- a/data/lib/bzpage.js
+++ b/data/lib/bzpage.js
@@ -329,43 +329,25 @@ function setConfigurationButton () {
}
/**
- * dd
- *
- * @return Element with the href attribute containng the information
- */
-function getOptionTableCell(tableId, label) {
- var cleanLabelRE = new RegExp("^\\s*([^.:]*):?\\s*$");
- label = label.trim().replace(cleanLabelRE,"$1").toLowerCase();
-
- var rows = document.getElementById(tableId).getElementsByTagName("tr");
- var ourLine = Array.filter(rows, function(row) {
- var curLabel = row.getElementsByTagName("td")[0].textContent.toLowerCase();
- curLabel = curLabel.replace(cleanLabelRE,"$1");
- return (curLabel === label); // maybe this could be a RE match instead
- });
-
- if (ourLine.length > 0) {
- return ourLine[0].getElementsByTagName("td")[1].
- getElementsByTagName("a")[0];
- }
- return null;
-}
-
-
-/**
* Complete startup, mainly run alternate inits for non-standard BZ with proper
* arguments
*
*/
function completeInit() {
- var attachments = getAttachments();
+ // FIXME: add flags, and priority or others bits.
+ var things = {
+ attachments: new AttachList(document),
+ comments: new CommentList(document)
+ };
if (RHBZinit) {
- RHBZinit(attachments);
+ RHBZinit(things);
}
+ things.comments.colorComments();
+
if (tweakBugzilla && config.verboseInlineHistory) {
- tweakBugzilla(attachments, constantData);
+ tweakBugzilla(things, constantData);
}
}
@@ -398,6 +380,13 @@ function startup() {
}
}
+ // Prepare for adding external bugs
+ var a0Elements = document.getElementsByName("a0");
+ if (a0Elements.length > 0) {
+ var extBugsHeadline = a0Elements[a0Elements.length - 1];
+ extBugsHeadline.setAttribute("id", "external_bugs_headline");
+ }
+
// TODO Probably could be ignored ... used only once on line 973 of
// rhbzpage.js
// if (parseAbrtBacktraces && this.RE.Abrt.test(getSummary())) {
@@ -408,8 +397,6 @@ function startup() {
setConfigurationButton();
submitHandlerInstalled = false;
- checkComments();
-
self.postMessage(new Message("GetInstalledPackages", {
location: window.location.href,
login: getLogin()
diff --git a/data/lib/collectingMetadata.js b/data/lib/collectingMetadata.js
new file mode 100644
index 0000000..6fe57a4
--- /dev/null
+++ b/data/lib/collectingMetadata.js
@@ -0,0 +1,188 @@
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+"use strict";
+
+function Comment(comment) {
+ var nameSpan = comment.querySelector(".bz_comment_user a.email");
+ var timeSpan = comment.getElementsByClassName("bz_comment_time")[0];
+
+ this.author = parseMailto(nameSpan).trim();
+ this.element = comment;
+ this.date = parseBZCommentDate(timeSpan.textContent.trim());
+ this.timeSpan = timeSpan;
+}
+
+Comment.prototype.getText = function getText() {
+ return this.element.getElementsByTagName("pre")[0].textContent.trim();
+}
+
+function CommentList(doc) {
+ var commentElems = document.getElementById("comments").
+ getElementsByClassName("bz_comment");
+ var comments = {};
+ Array.forEach(commentElems, function(item) {
+ var com = new Comment(item);
+ if (com.element) {
+ comments[ISODateString(com.date)] = com;
+ }
+ });
+ this.comments = comments;
+}
+
+/**
+ * Set background color of all comments made by reporter in ReporterColor color
+ *
+ */
+CommentList.prototype.colorComments = function colorComments() {
+ var reporter = getReporter();
+ var com = null;
+ for (var idx in this.comments) {
+ com = this.comments[idx];
+ if (com.author === reporter) {
+ com.element.style.backgroundColor = ReporterColor.toString();
+ }
+ }
+}
+
+CommentList.prototype.getAllCommentsText = function getAllCommentsText() {
+ var outStr = "";
+ for (var idx in this.comments) {
+ outStr += this.comments[idx].getText() + "\n";
+ }
+ return outStr;
+}
+// -----------------------------------------------------------
+
+/**
+ * Parse the row with the attachment and create new Attachment object
+ *
+ * @param DOM
+ * element to be parsed
+ *
+ * TODO error handling is missing ... it's bleee
+ *
+ * [ attName, id, MIMEtype, size, inElem ];
+ */
+function Attachment(inElem) {
+ // Skip over obsolete attachments
+ if (inElem.getElementsByClassName("bz_obsolete").length > 0) {
+ return; // FIXME how NOT to create an object?
+ }
+
+ // getting name of the attachment
+ this.name = inElem.getElementsByTagName("b")[0].textContent.trim();
+
+ // TODO probably could use url.URL object
+ var aHrefsArr = inElem.getElementsByTagName("a");
+ var aHref = Array.filter(aHrefsArr, function(x) {
+ return x.textContent.trim() === "Details";
+ })[0];
+ this.id = parseURL(aHref.getAttribute("href")).params.id;
+
+ // getting MIME type and size
+ var stringArray = inElem.getElementsByClassName("bz_attach_extra_info")[0].
+ textContent.replace(/[\n ()]+/g, " ").trim().split(", ");
+ this.size = parseInt(stringArray[0], 10);
+ this.mimeType = stringArray[1].split(" ")[0];
+ this.element = inElem;
+};
+
+Attachment.prototype.isBadMIME = function isBadMIME() {
+ var badMIMEArray = [ "application/octet-stream", "text/x-log", "undefined" ];
+ return isInList(this.mimeType, badMIMEArray);
+};
+
+Attachment.prototype.checkXorgLink = function checkXorgLink() {
+ var elemS = this.element.getElementsByTagName("td");
+ var elem = elemS[elemS.length - 1];
+ createDeadLink("xorgLogAnalyzeLink", "check", elem,
+ analyzeXorgLog, [this.id, "AnalyzeXorgLogBacktrace"], "br");
+};
+
+Attachment.prototype.isParsed = function isParsed() {
+ var titleParsedAttachment = "Part of the thread where crash happened";
+ return (new RegExp(titleParsedAttachment).test(this.name));
+};
+
+// ----------------------------------------------------------------------------
+function AttachList(doc) {
+ this.attachments = [];
+ var attach = {};
+ var attElements = doc.getElementById("attachment_table").
+ getElementsByTagName("tr");
+ // FIXME change into list of objects and both comments and
+ // attachments (and something else?) should be properties of one
+ // huge object
+ for ( var i = 1, ii = attElements.length - 1; i < ii; i++) {
+ attach = new Attachment(attElements[i]);
+ if (attach.id) {
+ this.attachments.push(attach);
+ }
+ }
+}
+
+AttachList.prototype.getBadAttachments = function getBadAttachments() {
+ return this.attachments.filter(function(att) {
+ return (att.isBadMIME());
+ });
+}
+
+/**
+ * Add a link opening selected lines of Xorg.0.log
+ */
+AttachList.prototype.addCheckXorgLogLink = function addCheckXorgLogLink() {
+ if (config.XorgLogAnalysis) {
+ this.getXorgList().
+ forEach(function (att) {
+ att.checkXorgLink();
+ });
+ }
+}
+
+/**
+ * Make it sailent that the some attachments with bad MIME type are present
+ *
+ * @param atts
+ * Array of attachments subarrays
+ * @return none
+ */
+AttachList.prototype.markBadAttachments = function markBadAttachments() {
+ if (!constantData.passwordState.passAvailable) {
+ console.log("markBadAttachments : No password, no XML-RPC calls; sorry");
+ return null;
+ }
+
+ var badAttachments = this.getBadAttachments();
+
+ if (badAttachments.length > 0) {
+ var titleElement = document.
+ getElementsByClassName("bz_alias_short_desc_container")[0];
+ titleElement.style.backgroundColor = "olive";
+
+ createDeadLink("fixAllButton", "Fix all", titleElement, function() {
+ Array.forEach(badAttachments, function(x) {
+ fixAttachById(x.id, constantData.XMLRPCData[window.location.hostname].url);
+ });
+ }, [], false, null, "f");
+ badAttachments.forEach(function(x, i, a) {
+ addTextLink(x, constantData.XMLRPCData[window.location.hostname].url);
+ });
+ }
+};
+
+AttachList.prototype.getParsedAttachments = function getParsedAttachments() {
+ return this.attachments.filter(function (att) {
+ return (att.isParsed());
+ });
+};
+
+AttachList.prototype.getXorgList = function getXorgList() {
+ return this.attachments.filter(function (value) {
+ // Xorg.0.log must be text, otherwise we cannot parse it
+ return (/[xX].*log/.test(value.name) && /text/.test(value.mimeType));
+ });
+};
+
+AttachList.prototype.forEach = function forEach(fce) {
+ this.attachments.forEach(fce);
+};
diff --git a/data/lib/otherButtons.js b/data/lib/otherButtons.js
index 31a4dd8..6935b8e 100644
--- a/data/lib/otherButtons.js
+++ b/data/lib/otherButtons.js
@@ -3,30 +3,6 @@
"use strict";
/**
- * Set background color of all comments made by reporter in ReporterColor color
- *
- */
-function checkComments() {
- var reporter = getReporter();
- commentsWalker(function(x) {
- var email = parseMailto(x.getElementsByClassName("vcard")[0]
- .getElementsByTagName("a")[0]);
- if (email.indexOf(reporter) != -1) {
- x.style.backgroundColor = ReporterColor.toString();
- }
- });
-}
-
-function collectComments() {
- var outStr = "";
- commentsWalker(function(x) {
- outStr += x.getElementsByTagName("pre")[0].textContent
- + "\n";
- });
- return outStr.trim();
-}
-
-/**
* Find default assignee based on the current component
*
* @return String what would be a default assignee if we haven't set it up.
@@ -119,7 +95,7 @@ function addingEmbelishments(logList) {
&& (!FillMagicDoneRE.test(getSummary()))
&& (maintCCAddr == "xgl-maint@redhat.com")) {
// Add find chip magic button
- fillInChipMagic(logList[0][1]);
+ fillInChipMagic(logList[0].id);
}
// Add links for creating new bug in the same product
@@ -138,10 +114,13 @@ function addingEmbelishments(logList) {
* String with the IsueTracker numbers
* @return none
*/
-function setBranding(xLogAtts) {
+function setBranding(things) {
var brandColor = {};
var TriagedColor = {};
+ var atts = things.attachments;
+ var xLogAtts = atts.getXorgList();
+
var ITbutton = document.getElementById("cf_issuetracker");
var its = ITbutton ? ITbutton.value.trim() : "";
diff --git a/data/lib/util.js b/data/lib/util.js
index 92b9436..b128d48 100644
--- a/data/lib/util.js
+++ b/data/lib/util.js
@@ -68,8 +68,12 @@ function parseXMLfromString (inStuff) {
* Get a bug no
*/
function getBugNo() {
- console.log("bugNo = " + document.getElementsByName("id")[0].value);
- return document.getElementsByName("id")[0].value;
+ var bugNoElem = document.forms.namedItem("changeform").elements["id"];
+ if (bugNoElem) {
+ return bugNoElem.value;
+ } else {
+ return null;
+ }
}
/**
@@ -210,6 +214,29 @@ function getISODate(dateStr) {
}
/**
+ * format Date object as ISO-8601 formatted date string
+ *
+ * @param d Date
+ * @return String with date formatted
+ * @url https://developer.mozilla.org/en/JavaScript/Reference\
+ /Global_Objects/Date#Example.3a_ISO_8601_formatted_dates
+ * outputs something like 2009-09-28T19:03:12Z
+ */
+function ISODateString(d) {
+ function pad(n) {
+ return n<10 ? '0'+n : n
+ }
+
+ return d.getUTCFullYear()+'-'
+ + pad(d.getUTCMonth()+1)+'-'
+ + pad(d.getUTCDate())+'T'
+ + pad(d.getUTCHours())+':'
+ + pad(d.getUTCMinutes())+':'
+ + pad(d.getUTCSeconds())+'Z';
+}
+
+
+/**
* Check whether an item is member of the list. Idea is just to make long if
* commands slightly more readable.
*
@@ -220,7 +247,7 @@ function getISODate(dateStr) {
* @return position of the string in the list, or -1 if none found.
*/
function isInList(mbr, list) {
- if (!list) {
+ if (!Array.isArray(list)) {
return false;
}
return (list.indexOf(mbr) !== -1);