⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 92135 in webkit


Ignore:
Timestamp:
Aug 1, 2011, 12:25:00 PM (15 years ago)
Author:
abarth@webkit.org
Message:

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:
Location:
trunk/Tools
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Bugzilla.js

    r89588 r92135  
    2424 */
    2525
    26 function Bugzilla(baseURL) {
    27     this.baseURL = baseURL;
    28     this._cache = {};
    29 }
     26var bugzilla = bugzilla || {};
    3027
    31 Bugzilla.prototype = {
    32     quickSearch: function(query, callback) {
    33         var cacheKey = 'quickSearch_' + query;
    34         if (cacheKey in this._cache) {
    35             callback(this._cache[cacheKey]);
    36             return;
    37         }
     28(function() {
    3829
    39         var callbacksCacheKey = 'quickSearchCallbacks_' + query;
    40         if (callbacksCacheKey in this._cache) {
    41             this._cache[callbacksCacheKey].push(callback);
    42             return;
    43         }
    44 
    45         this._cache[callbacksCacheKey] = [callback];
    46 
    47         var queryParameters = {
    48             ctype: 'rss',
    49             order: 'bugs.bug_id desc',
    50             quicksearch: query,
    51         };
    52 
    53         var self = this;
    54         fetchResource(this.baseURL + 'buglist.cgi', 'POST', queryParameters, function(xhr) {
    55             var entries = xhr.responseXML.getElementsByTagName('entry');
    56             var results = Array.prototype.map.call(entries, function(entry) {
    57                 var container = document.createElement('div');
    58                 container.innerHTML = entry.getElementsByTagName('summary')[0].textContent;
    59                 var statusRow = container.querySelector('tr.bz_feed_bug_status');
    60                 return {
    61                     title: entry.getElementsByTagName('title')[0].textContent,
    62                     url: entry.getElementsByTagName('id')[0].textContent,
    63                     status: statusRow.cells[1].textContent,
    64                 };
    65             });
    66 
    67             self._cache[cacheKey] = results;
    68 
    69             var callbacks = self._cache[callbacksCacheKey];
    70             delete self._cache[callbacksCacheKey];
    71 
    72             callbacks.forEach(function(callback) {
    73                 callback(results);
    74             });
    75         });
    76     },
     30var kOpenStatuses = {
     31    UNCONFIRMED: true,
     32    NEW: true,
     33    ASSIGNED: true,
     34    REOPENED: true,
    7735};
    7836
    79 Bugzilla.isOpenStatus = function(status) {
    80     const openStatuses = {
    81         UNCONFIRMED: true,
    82         NEW: true,
    83         ASSIGNED: true,
    84         REOPENED: true,
     37var g_searchCache = new base.AsynchronousCache(function(query, callback) {
     38    var url = config.kBugzillaURL + '/buglist.cgi?' + $.param({
     39        ctype: 'rss',
     40        order: 'bugs.bug_id desc',
     41        quicksearch: query,
     42    });
    8543
    86     };
    87     return status in openStatuses;
     44    $.get(url, function(responseXML) {
     45        var entries = responseXML.getElementsByTagName('entry');
     46        var results = Array.prototype.map.call(entries, function(entry) {
     47            var container = document.createElement('div');
     48            // FIXME: Is this an XSS risk?
     49            container.innerHTML = entry.getElementsByTagName('summary')[0].textContent;
     50            var statusRow = container.querySelector('tr.bz_feed_bug_status');
     51            return {
     52                title: entry.getElementsByTagName('title')[0].textContent,
     53                url: entry.getElementsByTagName('id')[0].textContent,
     54                status: statusRow.cells[1].textContent,
     55            };
     56        });
     57        callback(results);
     58    });
     59});
     60
     61bugzilla.quickSearch = function(query, callback)
     62{
     63    g_searchCache.get(query, callback);
     64};
     65
     66bugzilla.isOpenStatus = function(status)
     67{
     68    return status in kOpenStatuses;
    8869};
    8970
    9071// This value is built-in to all Bugzilla installations. See <http://webkit.org/b/61660>.
    91 Bugzilla.maximumBugTitleLength = 255;
     72bugzilla.kMaximumBugTitleLength = 255;
     73
     74})();
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FailingTestsBugForm.js

    r91538 r92135  
    2424 */
    2525
    26 function FailingTestsBugForm(bugzilla, tester, failingBuildName, passingBuildName, failingTests) {
    27     TestRelatedBugForm.call(this, bugzilla, tester);
     26function FailingTestsBugForm(tester, failingBuildName, passingBuildName, failingTests) {
     27    TestRelatedBugForm.call(this, tester);
    2828
    2929    this._failingBuildName = failingBuildName;
     
    8080        var title = titlePrefix + this._failingTests.join(', ') + titleSuffix;
    8181
    82         if (title.length <= Bugzilla.maximumBugTitleLength)
     82        if (title.length <= bugzilla.kMaximumBugTitleLength)
    8383            return title;
    8484
     
    8686        if (pathPrefix) {
    8787            title = titlePrefix + this._failingTests.length + ' ' + pathPrefix + ' tests' + titleSuffix;
    88             if (title.length <= Bugzilla.maximumBugTitleLength)
     88            if (title.length <= bugzilla.kMaximumBugTitleLength)
    8989                return title;
    9090        }
     
    9292        title = titlePrefix + this._failingTests.length + ' tests' + titleSuffix;
    9393
    94         console.assert(title.length <= Bugzilla.maximumBugTitleLength);
     94        console.assert(title.length <= bugzilla.kMaximumBugTitleLength);
    9595        return title;
    9696    },
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FailingTestsBugForm_unittests.js

    r91538 r92135  
    2929
    3030function createTestForm(testerName, failingBuildName, passingBuildName, failingTests) {
    31     var mockBugzilla = {};
    32     mockBugzilla.baseURL = '[BUGZILLA BASE URL]';
    33 
    3431    var mockBuildbot = {};
    3532    mockBuildbot.parseBuildName = function(buildName) {
     
    4845    }
    4946
    50     return new FailingTestsBugForm(mockBugzilla, mockBuilder, failingBuildName, passingBuildName, failingTests);
     47    return new FailingTestsBugForm(mockBuilder, failingBuildName, passingBuildName, failingTests);
    5148}
    5249
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FlakyTestBugForm.js

    r91278 r92135  
    2424 */
    2525
    26 function FlakyTestBugForm(bugzilla, tester, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount) {
    27     TestRelatedBugForm.call(this, bugzilla, tester);
     26function FlakyTestBugForm(tester, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount) {
     27    TestRelatedBugForm.call(this, tester);
    2828
    2929    this._failingBuildNames = failingBuildNames;
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FlakyTestBugForm_unittests.js

    r91278 r92135  
    2929
    3030function createTestForm(failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount) {
    31     var mockBugzilla = {};
    32     mockBugzilla.baseURL = '[BUGZILLA BASE URL]';
    33 
    3431    var mockBuildbot = {};
    3532    mockBuildbot.parseBuildName = function(buildName) {
     
    4845    }
    4946
    50     return new FlakyTestBugForm(mockBugzilla, mockBuilder, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount);
     47    return new FlakyTestBugForm(mockBuilder, failingBuildNames, failingTest, oldestAnalyzedBuild, newestAnalyzedBuild, analyzedBuildCount);
    5148}
    5249
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/NewBugForm.js

    r90814 r92135  
    2424 */
    2525
    26 function NewBugForm(bugzilla) {
    27     this._bugzilla = bugzilla;
     26function NewBugForm() {
    2827}
    2928
     
    5352        var form = document.createElement('form');
    5453        form.method = 'POST';
    55         form.action = this._bugzilla.baseURL + 'enter_bug.cgi';
     54        form.action = config.kBugzillaURL + '/enter_bug.cgi';
    5655
    5756        for (var key in formData) {
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/NewBugForm_unittests.js

    r90814 r92135  
    4141
    4242function createTestForm() {
    43     var mockBugzilla = {};
    44     mockBugzilla.baseURL = 'http://bugs.example.com/';
    45 
    46     var form = new NewBugForm(mockBugzilla);
     43    var form = new NewBugForm();
    4744    for (var key in testFormData) {
    4845        form[key] = testFormData[key].value;
     
    6360    equal(formElement.tagName, 'FORM');
    6461    equal(formElement.method, 'POST');
    65     equal(formElement.action, 'http://bugs.example.com/enter_bug.cgi');
     62    equal(formElement.action, 'https://bugs.webkit.org/enter_bug.cgi');
    6663});
    6764
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/TestRelatedBugForm.js

    r91272 r92135  
    2424 */
    2525
    26 function TestRelatedBugForm(bugzilla, tester) {
    27     NewBugForm.call(this, bugzilla);
     26function TestRelatedBugForm(tester) {
     27    NewBugForm.call(this);
    2828
    2929    this._tester = tester;
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/TestRelatedBugForm_unittests.js

    r91272 r92135  
    2929
    3030function createTestForm(testerName) {
    31     var mockBugzilla = {};
    32     mockBugzilla.baseURL = '[BUGZILLA BASE URL]';
    33 
    3431    var mockBuildbot = {};
    3532    mockBuildbot.parseBuildName = function(buildName) {
     
    4845    }
    4946
    50     return new TestRelatedBugForm(mockBugzilla, mockBuilder);
     47    return new TestRelatedBugForm(mockBuilder);
    5148}
    5249
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js

    r91546 r92135  
    2424 */
    2525
    26 function ViewController(buildbot, bugzilla) {
     26function ViewController(buildbot) {
    2727    this._buildbot = buildbot;
    28     this._bugzilla = bugzilla;
    2928    this._navigationID = 0;
    3029
     
    104103
    105104                if (passingBuildName || !stillFetchingData) {
    106                     var bugForm = new FailingTestsBugForm(self._bugzilla, builder, buildName, passingBuildName, failingTestNames);
     105                    var bugForm = new FailingTestsBugForm(builder, buildName, passingBuildName, failingTestNames);
    107106                    item.appendChild(self._domForNewAndExistingBugs(builder, failingTestNames, bugForm))
    108107                }
     
    245244
    246245    _domForAuxiliaryUIElements: function() {
    247         if (!this._bugzilla)
    248             return document.createDocumentFragment();
    249 
    250246        var aside = document.createElement('aside');
    251247        aside.appendChild(document.createTextNode('Something not working? Have an idea to improve this page? '));
     
    262258            short_desc: 'TestFailures page needs more unicorns!',
    263259        };
    264         link.href = addQueryParametersToURL(this._bugzilla.baseURL + 'enter_bug.cgi', queryParameters);
     260        link.href = addQueryParametersToURL(config.kBugzillaURL + 'enter_bug.cgi', queryParameters);
    265261        link.target = '_blank';
    266262
     
    328324        var result = document.createDocumentFragment();
    329325
    330         if (!this._bugzilla)
    331             return result;
    332 
    333326        var container = document.createElement('p');
    334327        result.appendChild(container);
     
    341334        bugsContainer.appendChild(document.createTextNode('Searching for bugs related to ' + (failingTests.length > 1 ? 'these tests' : 'this test') + '\u2026'));
    342335
    343         this._bugzilla.quickSearch('ALL ' + failingTests.join('|'), function(bugs) {
     336        bugzilla.quickSearch('ALL ' + failingTests.join('|'), function(bugs) {
    344337            if (!bugs.length) {
    345338                bugsContainer.parentNode.removeChild(bugsContainer);
     
    368361            }
    369362
    370             var openBugs = bugs.filter(function(bug) { return Bugzilla.isOpenStatus(bug.status) });
    371             var closedBugs = bugs.filter(function(bug) { return !Bugzilla.isOpenStatus(bug.status) });
     363            var openBugs = bugs.filter(function(bug) { return bugzilla.isOpenStatus(bug.status) });
     364            var closedBugs = bugs.filter(function(bug) { return !bugzilla.isOpenStatus(bug.status) });
    372365
    373366            list.appendChildren(openBugs.map(bugToListItem));
     
    455448
    456449                    var failingBuildNames = failures.map(function(historyItem) { return historyItem.build });
    457                     var bugForm = new FlakyTestBugForm(self._bugzilla, builder, failingBuildNames, testName, allBuilds.last(), allBuilds[0], allBuilds.length);
     450                    var bugForm = new FlakyTestBugForm(builder, failingBuildNames, testName, allBuilds.last(), allBuilds[0], allBuilds.length);
    458451                    container.appendChild(self._domForNewAndExistingBugs(builder, [testName], bugForm));
    459452                }
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/config.js

    r92060 r92135  
    3131
    3232config.kTracURL = 'http://trac.webkit.org';
     33config.kBugzillaURL = 'https://bugs.webkit.org';
    3334
    3435config.kRevisionAttr = 'data-revision';
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/garden-o-matic.html

    r92134 r92135  
    3333<script src="base.js"></script>
    3434<script src="Trac.js"></script>
     35<script src="Bugzilla.js"></script>
    3536<script src="builders.js"></script>
    3637<script src="checkout.js"></script>
  • trunk/Tools/BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/index.html

    r91538 r92135  
    5353    <script src="WebKitBuildbot.js"></script>
    5454    <script>
    55         var viewController = new ViewController(new WebKitBuildbot(), new Bugzilla('https://bugs.webkit.org/'));
     55        var viewController = new ViewController(new WebKitBuildbot());
    5656    </script>
    5757</head>
  • trunk/Tools/ChangeLog

    r92134 r92135  
     12011-08-01  Adam Barth  <abarth@webkit.org>
     2
     3        Refactor bugzilla.js for use by garden-o-matic
     4        https://bugs.webkit.org/show_bug.cgi?id=65450
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        This patch refactors bugzilla.js to use the AsynchronousCache and
     9        updates the style to use a module instead of an object.  This patch
     10        then fixes all the existing code that uses this class to use the new
     11        API style.
     12
     13        This main benefit of this patch is we remove the tricky manual caching
     14        and this code is now available to use in garden-o-matic (since the
     15        dependency on Utilities.js is now gone).
     16
     17        I ran all the unit tests and poked around in TestFailures a bit to see
     18        that everything seemed to be working properly.
     19
     20        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/Bugzilla.js:
     21        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FailingTestsBugForm.js:
     22        (FailingTestsBugForm):
     23        (FailingTestsBugForm.prototype._createBugTitle):
     24        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FailingTestsBugForm_unittests.js:
     25        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FlakyTestBugForm.js:
     26        (FlakyTestBugForm):
     27        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/FlakyTestBugForm_unittests.js:
     28        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/NewBugForm.js:
     29        (NewBugForm):
     30        (NewBugForm.prototype.domElement):
     31        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/NewBugForm_unittests.js:
     32        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/TestRelatedBugForm.js:
     33        (TestRelatedBugForm):
     34        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/TestRelatedBugForm_unittests.js:
     35        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/ViewController.js:
     36        (ViewController.prototype._displayBuilder.start):
     37        (ViewController.prototype._displayBuilder):
     38        (ViewController.prototype._domForAuxiliaryUIElements):
     39        (ViewController.prototype._domForNewAndExistingBugs.bugzilla.quickSearch):
     40        (ViewController.prototype._domForPossiblyFlakyTests.flakyList.appendChildren):
     41        (ViewController.prototype._domForPossiblyFlakyTests):
     42        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/config.js:
     43        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/garden-o-matic.html:
     44        * BuildSlaveSupport/build.webkit.org-config/public_html/TestFailures/index.html:
     45
    1462011-08-01  Adam Barth  <abarth@webkit.org>
    247
Note: See TracChangeset for help on using the changeset viewer.