diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-08-19 23:13:19 -0400 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-08-19 23:13:19 -0400 |
commit | 7d881cf6e9d5e5589827ecc5c17bdfa78fe2b513 (patch) | |
tree | 391a9c2bfaa17ab5d94aea04b9d12b6e281a662a /lib | |
parent | 33fcda043c9639220cd27429410be128363a69c1 (diff) | |
download | bugzilla-triage-7d881cf6e9d5e5589827ecc5c17bdfa78fe2b513.tar.gz |
Actually really fix #43 and simplification of collecting information.0.20
Release 0.20
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bzpage.js | 95 | ||||
-rw-r--r-- | lib/rhbzpage.js | 31 | ||||
-rw-r--r-- | lib/util.js | 4 |
3 files changed, 51 insertions, 79 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js index 0212eac..de03107 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -104,10 +104,6 @@ var BZPage = function BZPage(win, config) { this.submitHandlerInstalled = false; this.bugNo = util.getBugNo(this.doc.location.toString()); - this.reporter = this.getReporter(); - this.product = this.getOptionValue("product"); - this.component = this.getOptionValue("component"); - this.version = this.getVersion(); this.title = this.doc.getElementById("short_desc_nonedit_display").textContent; this.CCList = this.getCCList(); @@ -496,8 +492,9 @@ BZPage.prototype.setConfigurationButton = function setConfigurationButton () { }; /* - * From <a href="mailto:email"> element diggs out just plain email - * address + * From <a> element diggs out just plain email address + * Note that bugzilla.gnome.org doesn't have mailto: url but + * https://bugzilla.gnome.org/page.cgi?id=describeuser.html&login=mcepl%40redhat.com * * @param aElement Element with href attribute or something else * @return String with the address or null @@ -505,9 +502,11 @@ BZPage.prototype.setConfigurationButton = function setConfigurationButton () { */ BZPage.prototype.parseMailto = function parseMailto(aElement) { var emailStr = "", hrefStr = ""; + // use url utils if (aElement) { hrefStr = decodeURIComponent(aElement.getAttribute("href")); emailStr = hrefStr.split(":")[1]; + // if (emailStr === undefined) { var params = util.getParamsFromURL("https://" + this.hostname + "/" + hrefStr); emailStr = decodeURI(params['login']); @@ -523,33 +522,25 @@ BZPage.prototype.parseMailto = function parseMailto(aElement) { * @return string */ BZPage.prototype.getReporter = function getReporter () { - var reporterElement = this.doc. - querySelector("#bz_show_bug_column_2 > table .vcard:first-of-type > a"); + var reporterElement = this.getOptionTableCell("bz_show_bug_column_2", "Reported"); // RH Bugzilla after upgrade to 3.6.2 moved the information to other column if (!reporterElement) { - reporterElement = this.doc. - querySelector("#bz_show_bug_column_1 > table .vcard:first-of-type > a"); + reporterElement = this.getOptionTableCell("bz_show_bug_column_1", "Reported", true); } + // Maemo calls the label "Reporter" and it doesn't have ids on table columns ... TODO(maemo) + return this.parseMailto(reporterElement); }; -/** - * Get the current version of the Fedora release ... even if changed meanwhile - * by bug triager. - * - * @return string (integer for released Fedora, float for RHEL, rawhide) - */ -BZPage.prototype.getVersion = function getVersion () { - var verStr = this.getOptionValue("version").toLowerCase(); - var verNo = 0; - if (/rawhide/.test(verStr)) { - verNo = 999; - } else { - verNo = Number(verStr); +BZPage.prototype.getComponent = function getComponent() { + var elem = this.doc.getElementById("component"); + if (elem) { + return elem.value; } - return verNo; + return null; }; + BZPage.prototype.commentsWalker = function commentsWalker (fce) { var comments = this.doc.getElementById("comments").getElementsByClassName( "bz_comment"); @@ -564,10 +555,11 @@ BZPage.prototype.commentsWalker = function commentsWalker (fce) { */ BZPage.prototype.checkComments = function checkComments () { var that = this; + var reporterRE = new RegExp(this.getReporter()); this.commentsWalker(function(x) { var email = that.parseMailto(x.getElementsByClassName("vcard")[0] .getElementsByTagName("a")[0]); - if (new RegExp(that.reporter).test(email)) { + if (reporterRE.test(email)) { x.style.backgroundColor = that.ReporterColor.toString(); } }); @@ -683,7 +675,7 @@ BZPage.prototype.idContainsWord = function idContainsWord (id, str) { // For those who don't have particular element at all or if it is empty return false; } - return (kwd.trim().indexOf(str) !== -1); + return (util.isInList(str, kwd.trim().split(/,\s*/))); }; /** @@ -697,42 +689,28 @@ BZPage.prototype.hasKeyword = function hasKeyword (str) { }; /** + +@return Element with the href attribute containng the information */ BZPage.prototype.getOptionTableCell = function getOptionTableCell(tableId, label) { - var cleanLabelRE = /^\s*([^. :]*):?\s*$/; - label = label.replace(cleanLabelRE,"$1").toLowerCase(); + var cleanLabelRE = /^\s*([^.:]*):?\s*$/; + label = label.trim().replace(cleanLabelRE,"$1").toLowerCase(); + var rows = this.doc.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); + return (curLabel === label); // maybe this could be a RE match instead }); + if (ourLine.length > 0) { - return ourLine[0].getElementsByTagName("td")[1].textContent; + return ourLine[0].getElementsByTagName("td")[1]. + getElementsByTagName("a")[0]; } return null; }; /** - * - */ -BZPage.prototype.getOptionValue = function getOptionValue (id) { - // Some special bugs don't have version for example - var element = this.doc.getElementById(id); - if (element) { - return element.value; - } else { - // this doesn't work on bugzilla.gnome.org - element = this.getOptionTableCell("bug_summary", id); - if (element) { - return element; - } - throw new Error("Failed to find element with id = " + id); - return null; - } -}; - -/** * Set the bug to NEEDINFO state * * Working function. @@ -749,25 +727,12 @@ BZPage.prototype.setNeedinfoReporter = function setNeedinfoReporter () { * */ BZPage.prototype.getOwner = function getOwner () { - var priorityParent = this.doc.querySelector("label[for~='target_milestone']") - .parentNode.parentNode.parentNode; - var assigneeAElement = priorityParent.querySelector("tr:nth-of-type(1) a.email"); + // TODO(maemo) doesn't work on maemo + var assigneeAElement = this.getOptionTableCell("bz_show_bug_column_1","Assigned To"); return this.parseMailto(assigneeAElement); }; /** - * Get login of the currently logged-in user. - * - * @return String with the login name of the currently logged-in user - */ -BZPage.prototype.getLogin = function getLogin () { - var lastLIElement = this.doc.querySelector("#header ul.links li:last-of-type"); - var loginArr = lastLIElement.textContent.split("\n"); - var loginStr = loginArr[loginArr.length - 1].trim(); - return loginStr; -}; - -/** * Return maintainer which is per default by bugzilla * (which is not necessarily the one who is default maintainer per component) * @@ -967,7 +932,7 @@ BZPage.prototype.queryInNewTab = function(text, component, product) { BZPage.prototype.queryForSelection = function() { var text = this.getSelectionOrClipboard(); if (text) { - this.queryInNewTab(text, this.component); + this.queryInNewTab(text, this.getComponent()); } }; diff --git a/lib/rhbzpage.js b/lib/rhbzpage.js index b55e44b..3ae39be 100644 --- a/lib/rhbzpage.js +++ b/lib/rhbzpage.js @@ -61,11 +61,12 @@ var RHBugzillaPage = function RHBugzillaPage(win, config) { this.chipMagicInterestingLine = ""; this.login = this.getLogin(); + this.product = this.doc.getElementById("product").value; this.maintCCAddr = null; if (this.constantData.CCmaintainer) { this.maintCCAddr = util.filterByRegexp(this.constantData.CCmaintainer, - this.component); + this.getComponent()); } var ITbutton = this.doc.getElementById("cf_issuetracker"); @@ -135,7 +136,6 @@ var RHBugzillaPage = function RHBugzillaPage(win, config) { if (compElement && (compElement.options)) { this.doc.getElementById("component").addEventListener("change", function() { - that.component = that.getOptionValue("component"); that.changeAssignee("default"); }, false); } @@ -150,6 +150,18 @@ RHBugzillaPage.prototype = util.heir(BZPage); RHBugzillaPage.prototype.constructor = RHBugzillaPage; /** + * Get login of the currently logged-in user. + * + * @return String with the login name of the currently logged-in user + */ +RHBugzillaPage.prototype.getLogin = function getLogin () { + var lastLIElement = this.doc.querySelector("#header ul.links li:last-of-type"); + var loginArr = lastLIElement.textContent.split("\n"); + var loginStr = loginArr[loginArr.length - 1].trim(); + return loginStr; +}; + +/** * Find default assignee based on the current component * * @return String what would be a default assignee if @@ -157,7 +169,7 @@ RHBugzillaPage.prototype.constructor = RHBugzillaPage; */ RHBugzillaPage.prototype.getDefaultAssignee = function() { return util.filterByRegexp(this.constantData.defaultAssignee, - this.component).toLowerCase(); + this.getComponent()).toLowerCase(); }; /** @@ -346,12 +358,7 @@ RHBugzillaPage.prototype.isEnterprise = function() { * @return Boolean whether the bug has been triaged or not */ RHBugzillaPage.prototype.isTriaged = function() { - // First excceptions - if (this.version > 7 && this.version < 12) { - return this.doc.getElementById("bug_status").value.toUpperCase() !== "NEW"; - } else { // and then the rule return this.hasKeyword("Triaged"); - } }; /** @@ -373,7 +380,7 @@ RHBugzillaPage.prototype.setBranding = function() { brandColor = this.RHColor; } } else if (new RegExp("Fedora").test(this.product)) { - if (this.version === 999) { + if (this.doc.getElementById("version").value === "rawhide") { brandColor = this.RawhideColor; } else { brandColor = this.FedoraColor; @@ -421,7 +428,7 @@ RHBugzillaPage.prototype.setBranding = function() { // mark suspicious components var compElems; if (this.suspiciousComponents - && util.isInList(this.component, this.suspiciousComponents) + && util.isInList(this.getComponent(), this.suspiciousComponents) && (compElems = this.doc .getElementById("bz_component_edit_container"))) { compElems.style.background = "red none"; @@ -436,7 +443,7 @@ RHBugzillaPage.prototype.queryUpstream = function() { if (text) { text = encodeURIComponent(text.trim()); var queryUpstreamBugsURLArray = this.constantData.queryUpstreamBug; - var urlBase = util.filterByRegexp(queryUpstreamBugsURLArray, this.component); + var urlBase = util.filterByRegexp(queryUpstreamBugsURLArray, this.getComponent()); tabs.open({ url: urlBase + text, inBackground: true, @@ -453,7 +460,7 @@ RHBugzillaPage.prototype.queryUpstream = function() { RHBugzillaPage.prototype.sendBugUpstream = function() { var that = this; var urlStr = util.filterByRegexp(JSON.parse(self.data.load("newUpstreamBug.json")), this - .getOptionValue("component")); + .getComponent()); tabs.open({ url: urlStr, diff --git a/lib/util.js b/lib/util.js index 54af598..76c8a02 100644 --- a/lib/util.js +++ b/lib/util.js @@ -37,13 +37,13 @@ exports.heir = function heir(p) { /** * get parameters of URL as an object (name, value) */ -var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url) { +var getParamsFromURL = exports.getParamsFromURL = function getParamsFromURL (url, base) { if (!url || (url.toString().length === 0)) { throw new Error("Missing URL value!"); } if (!(url instanceof urlMod.URL)) { - url = new urlMod.URL(url.toString()); + url = new urlMod.URL(url.toString(), base); } var paramsArr = url.path.split("?"); |