Skip to content
Permalink
Browse files
Refactor bugzilla.js for use by garden-o-matic
https://bugs.webkit.org/show_bug.cgi?id=65450

Reviewed by Dimitri Glazkov.

This patch refactors bugzilla.js to use the AsynchronousCache and
updates the style to use a module instead of an object.  This patch
then fixes all the existing code that uses this class to use the new
API style.

This main benefit of this patch is we remove the tricky manual caching
and this code is now available to use in garden-o-matic (since the
dependency on Utilities.js is now gone).

I ran all the unit tests and poked around in TestFailures a bit to see
that everything seemed to be working properly.

* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Bugzilla.js:
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FailingTestsBugForm.js:
(FailingTestsBugForm):
(FailingTestsBugForm.prototype._createBugTitle):
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FailingTestsBugForm_unittests.js:
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FlakyTestBugForm.js:
(FlakyTestBugForm):
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FlakyTestBugForm_unittests.js:
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/NewBugForm.js:
(NewBugForm):
(NewBugForm.prototype.domElement):
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/NewBugForm_unittests.js:
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/TestRelatedBugForm.js:
(TestRelatedBugForm):
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/TestRelatedBugForm_unittests.js:
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js:
(ViewController.prototype._displayBuilder.start):
(ViewController.prototype._displayBuilder):
(ViewController.prototype._domForAuxiliaryUIElements):
(ViewController.prototype._domForNewAndExistingBugs.bugzilla.quickSearch):
(ViewController.prototype._domForPossiblyFlakyTests.flakyList.appendChildren):
(ViewController.prototype._domForPossiblyFlakyTests):
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/config.js:
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/garden-o-matic.html:
* BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/index.html:


Canonical link: https://commits.webkit.org/81278@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@92135 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Adam Barth committed Aug 1, 2011
1 parent e22c438 commit edf48f67eccdad6fb934558049ac783e535e1bd6
Showing 14 changed files with 110 additions and 100 deletions.
@@ -23,69 +23,52 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

function Bugzilla(baseURL) {
this.baseURL = baseURL;
this._cache = {};
}
var bugzilla = bugzilla || {};

Bugzilla.prototype = {
quickSearch: function(query, callback) {
var cacheKey = 'quickSearch_' + query;
if (cacheKey in this._cache) {
callback(this._cache[cacheKey]);
return;
}
(function() {

var callbacksCacheKey = 'quickSearchCallbacks_' + query;
if (callbacksCacheKey in this._cache) {
this._cache[callbacksCacheKey].push(callback);
return;
}

this._cache[callbacksCacheKey] = [callback];

var queryParameters = {
ctype: 'rss',
order: 'bugs.bug_id desc',
quicksearch: query,
};

var self = this;
fetchResource(this.baseURL + 'buglist.cgi', 'POST', queryParameters, function(xhr) {
var entries = xhr.responseXML.getElementsByTagName('entry');
var results = Array.prototype.map.call(entries, function(entry) {
var container = document.createElement('div');
container.innerHTML = entry.getElementsByTagName('summary')[0].textContent;
var statusRow = container.querySelector('tr.bz_feed_bug_status');
return {
title: entry.getElementsByTagName('title')[0].textContent,
url: entry.getElementsByTagName('id')[0].textContent,
status: statusRow.cells[1].textContent,
};
});

self._cache[cacheKey] = results;
var kOpenStatuses = {
UNCONFIRMED: true,
NEW: true,
ASSIGNED: true,
REOPENED: true,
};

var callbacks = self._cache[callbacksCacheKey];
delete self._cache[callbacksCacheKey];
var g_searchCache = new base.AsynchronousCache(function(query, callback) {
var url = config.kBugzillaURL + '/buglist.cgi?' + $.param({
ctype: 'rss',
order: 'bugs.bug_id desc',
quicksearch: query,
});

callbacks.forEach(function(callback) {
callback(results);
});
$.get(url, function(responseXML) {
var entries = responseXML.getElementsByTagName('entry');
var results = Array.prototype.map.call(entries, function(entry) {
var container = document.createElement('div');
// FIXME: Is this an XSS risk?
container.innerHTML = entry.getElementsByTagName('summary')[0].textContent;
var statusRow = container.querySelector('tr.bz_feed_bug_status');
return {
title: entry.getElementsByTagName('title')[0].textContent,
url: entry.getElementsByTagName('id')[0].textContent,
status: statusRow.cells[1].textContent,
};
});
},
};
callback(results);
});
});

Bugzilla.isOpenStatus = function(status) {
const openStatuses = {
UNCONFIRMED: true,
NEW: true,
ASSIGNED: true,
REOPENED: true,
bugzilla.quickSearch = function(query, callback)
{
g_searchCache.get(query, callback);
};

};
return status in openStatuses;
bugzilla.isOpenStatus = function(status)
{
return status in kOpenStatuses;
};

// This value is built-in to all Bugzilla installations. See <http://webkit.org/b/61660>.
Bugzilla.maximumBugTitleLength = 255;
bugzilla.kMaximumBugTitleLength = 255;

})();
@@ -23,8 +23,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

function FailingTestsBugForm(bugzilla, tester, failingBuildName, passingBuildName, failingTests) {
TestRelatedBugForm.call(this, bugzilla, tester);
function FailingTestsBugForm(tester, failingBuildName, passingBuildName, failingTests) {
TestRelatedBugForm.call(this, tester);

this._failingBuildName = failingBuildName;
this._passingBuildName = passingBuildName;
@@ -79,19 +79,19 @@ FailingTestsBugForm.prototype = {
var titleSuffix = ' failing on ' + this._tester.name;
var title = titlePrefix + this._failingTests.join(', ') + titleSuffix;

if (title.length <= Bugzilla.maximumBugTitleLength)
if (title.length <= bugzilla.kMaximumBugTitleLength)
return title;

var pathPrefix = longestCommonPathPrefix(this._failingTests);
if (pathPrefix) {
title = titlePrefix + this._failingTests.length + ' ' + pathPrefix + ' tests' + titleSuffix;
if (title.length <= Bugzilla.maximumBugTitleLength)
if (title.length <= bugzilla.kMaximumBugTitleLength)
return title;
}

title = titlePrefix + this._failingTests.length + ' tests' + titleSuffix;

console.assert(title.length <= Bugzilla.maximumBugTitleLength);
console.assert(title.length <= bugzilla.kMaximumBugTitleLength);
return title;
},

@@ -28,9 +28,6 @@
module('FailingTestsBugForm');

function createTestForm(testerName, failingBuildName, passingBuildName, failingTests) {
var mockBugzilla = {};
mockBugzilla.baseURL = '[BUGZILLA BASE URL]';

var mockBuildbot = {};
mockBuildbot.parseBuildName = function(buildName) {
var match = /(\d+)/.exec(buildName);
@@ -47,7 +44,7 @@ function createTestForm(testerName, failingBuildName, passingBuildName, failingT
return '[RESULTS PAGE URL ' + this.name + ', ' + buildName + ']';
}

return new FailingTestsBugForm(mockBugzilla, mockBuilder, failingBuildName, passingBuildName, failingTests);
return new FailingTestsBugForm(mockBuilder, failingBuildName, passingBuildName, failingTests);
}

test('keywords are set', 1, function() {
@@ -23,8 +23,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

function FlakyTestBugForm(bugzilla, tester, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount) {
TestRelatedBugForm.call(this, bugzilla, tester);
function FlakyTestBugForm(tester, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount) {
TestRelatedBugForm.call(this, tester);

this._failingBuildNames = failingBuildNames;
this._failingTest = failingTest;
@@ -28,9 +28,6 @@
module('FlakyTestBugForm');

function createTestForm(failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount) {
var mockBugzilla = {};
mockBugzilla.baseURL = '[BUGZILLA BASE URL]';

var mockBuildbot = {};
mockBuildbot.parseBuildName = function(buildName) {
var match = /(\d+)/.exec(buildName);
@@ -47,7 +44,7 @@ function createTestForm(failingBuildNames, failingTest, oldestAnalyzedBuild, new
return '[RESULTS PAGE URL ' + this.name + ', ' + buildName + ']';
}

return new FlakyTestBugForm(mockBugzilla, mockBuilder, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount);
return new FlakyTestBugForm(mockBuilder, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount);
}

const testCases = [
@@ -23,8 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

function NewBugForm(bugzilla) {
this._bugzilla = bugzilla;
function NewBugForm() {
}

NewBugForm.prototype = {
@@ -52,7 +51,7 @@ NewBugForm.prototype = {

var form = document.createElement('form');
form.method = 'POST';
form.action = this._bugzilla.baseURL + 'enter_bug.cgi';
form.action = config.kBugzillaURL + '/enter_bug.cgi';

for (var key in formData) {
var input = document.createElement('input');
@@ -40,10 +40,7 @@ const testFormData = {
};

function createTestForm() {
var mockBugzilla = {};
mockBugzilla.baseURL = 'http://bugs.example.com/';

var form = new NewBugForm(mockBugzilla);
var form = new NewBugForm();
for (var key in testFormData) {
form[key] = testFormData[key].value;
}
@@ -62,7 +59,7 @@ test('domElement() posts to enter_bug.cgi', 3, function() {
var formElement = createTestForm().domElement();
equal(formElement.tagName, 'FORM');
equal(formElement.method, 'POST');
equal(formElement.action, 'http://bugs.example.com/enter_bug.cgi');
equal(formElement.action, 'https://bugs.webkit.org/enter_bug.cgi');
});

test('domElement() contains only hidden input elements', 9, function() {
@@ -23,8 +23,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

function TestRelatedBugForm(bugzilla, tester) {
NewBugForm.call(this, bugzilla);
function TestRelatedBugForm(tester) {
NewBugForm.call(this);

this._tester = tester;

@@ -28,9 +28,6 @@
module('TestRelatedBugForm');

function createTestForm(testerName) {
var mockBugzilla = {};
mockBugzilla.baseURL = '[BUGZILLA BASE URL]';

var mockBuildbot = {};
mockBuildbot.parseBuildName = function(buildName) {
var match = /(\d+)/.exec(buildName);
@@ -47,7 +44,7 @@ function createTestForm(testerName) {
return '[RESULTS PAGE URL ' + this.name + ', ' + buildName + ']';
}

return new TestRelatedBugForm(mockBugzilla, mockBuilder);
return new TestRelatedBugForm(mockBuilder);
}

test('component and keywords are set', 2, function() {
@@ -23,9 +23,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

function ViewController(buildbot, bugzilla) {
function ViewController(buildbot) {
this._buildbot = buildbot;
this._bugzilla = bugzilla;
this._navigationID = 0;

var self = this;
@@ -103,7 +102,7 @@ ViewController.prototype = {
item.appendChild(self._domForRegressionRange(builder, buildName, passingBuildName, failingTestNames));

if (passingBuildName || !stillFetchingData) {
var bugForm = new FailingTestsBugForm(self._bugzilla, builder, buildName, passingBuildName, failingTestNames);
var bugForm = new FailingTestsBugForm(builder, buildName, passingBuildName, failingTestNames);
item.appendChild(self._domForNewAndExistingBugs(builder, failingTestNames, bugForm))
}
});
@@ -244,9 +243,6 @@ ViewController.prototype = {
},

_domForAuxiliaryUIElements: function() {
if (!this._bugzilla)
return document.createDocumentFragment();

var aside = document.createElement('aside');
aside.appendChild(document.createTextNode('Something not working? Have an idea to improve this page? '));
var link = document.createElement('a');
@@ -261,7 +257,7 @@ ViewController.prototype = {
cc: 'aroben@apple.com',
short_desc: 'TestFailures page needs more unicorns!',
};
link.href = addQueryParametersToURL(this._bugzilla.baseURL + 'enter_bug.cgi', queryParameters);
link.href = addQueryParametersToURL(config.kBugzillaURL + 'enter_bug.cgi', queryParameters);
link.target = '_blank';

return aside;
@@ -327,9 +323,6 @@ ViewController.prototype = {
_domForNewAndExistingBugs: function(tester, failingTests, bugForm) {
var result = document.createDocumentFragment();

if (!this._bugzilla)
return result;

var container = document.createElement('p');
result.appendChild(container);

@@ -340,7 +333,7 @@ ViewController.prototype = {

bugsContainer.appendChild(document.createTextNode('Searching for bugs related to ' + (failingTests.length > 1 ? 'these tests' : 'this test') + '\u2026'));

this._bugzilla.quickSearch('ALL ' + failingTests.join('|'), function(bugs) {
bugzilla.quickSearch('ALL ' + failingTests.join('|'), function(bugs) {
if (!bugs.length) {
bugsContainer.parentNode.removeChild(bugsContainer);
return;
@@ -367,8 +360,8 @@ ViewController.prototype = {
return item;
}

var openBugs = bugs.filter(function(bug) { return Bugzilla.isOpenStatus(bug.status) });
var closedBugs = bugs.filter(function(bug) { return !Bugzilla.isOpenStatus(bug.status) });
var openBugs = bugs.filter(function(bug) { return bugzilla.isOpenStatus(bug.status) });
var closedBugs = bugs.filter(function(bug) { return !bugzilla.isOpenStatus(bug.status) });

list.appendChildren(openBugs.map(bugToListItem));

@@ -454,7 +447,7 @@ ViewController.prototype = {
}));

var failingBuildNames = failures.map(function(historyItem) { return historyItem.build });
var bugForm = new FlakyTestBugForm(self._bugzilla, builder, failingBuildNames, testName, allBuilds.last(), allBuilds[0], allBuilds.length);
var bugForm = new FlakyTestBugForm(builder, failingBuildNames, testName, allBuilds.last(), allBuilds[0], allBuilds.length);
container.appendChild(self._domForNewAndExistingBugs(builder, [testName], bugForm));
}
});
@@ -30,6 +30,7 @@ config.kBuildersThatOnlyCompile = [
];

config.kTracURL = 'http://trac.webkit.org';
config.kBugzillaURL = 'https://bugs.webkit.org';

config.kRevisionAttr = 'data-revision';
config.kTestNameAttr = 'data-test-name';
@@ -32,6 +32,7 @@
<script src="config.js"></script>
<script src="base.js"></script>
<script src="Trac.js"></script>
<script src="Bugzilla.js"></script>
<script src="builders.js"></script>
<script src="checkout.js"></script>
<script src="results.js"></script>
@@ -52,7 +52,7 @@
<script src="WebKitBugzilla.js"></script>
<script src="WebKitBuildbot.js"></script>
<script>
var viewController = new ViewController(new WebKitBuildbot(), new Bugzilla('https://bugs.webkit.org/'));
var viewController = new ViewController(new WebKitBuildbot());
</script>
</head>
<body>

0 comments on commit edf48f6

Please sign in to comment.