2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 function RecentBuildsLoader(didLoadRecentBuildsCallback) {
27 this._didLoadRecentBuildsCallback = didLoadRecentBuildsCallback;
30 RecentBuildsLoader.prototype = {
31 start: function(builderName, maximumNumberOfBuilds) {
32 var url = this._buildbotBaseURL + "/json/builders/" + builderName + "/builds/?";
33 url += range(maximumNumberOfBuilds).map(function(n) { return "select=-" + (n + 1); }).join("&");
35 getResource(url, function(xhr) {
36 var data = JSON.parse(xhr.responseText);
38 Object.keys(data).forEach(function(buildNumber) {
39 var build = data[buildNumber];
42 revision: parseInt(build.properties.first(function(property) { return property[0] === "got_revision"; })[1], 10),
46 for (var stepIndex = 0; stepIndex < build.steps.length; ++stepIndex) {
47 var step = build.steps[stepIndex];
48 if (step.name === "layout-test") {
49 if (!("text" in step))
51 var strings = step.text;
52 for (var stringIndex = 0; stringIndex < strings.length; ++stringIndex) {
53 var match = /^(\d+) total leaks found/.exec(strings[stringIndex]);
56 buildInfo.leakCount = parseInt(match[1], 10);
59 } else if (step.name === "MasterShellCommand") {
60 if (!("urls" in step))
62 if (!("view results" in step.urls))
64 var url = step.urls["view results"];
65 buildInfo.url = self._buildbotBaseURL + url.replace(/\/results\.html$/, "") + "/";
68 if (buildInfo.leakCount && buildInfo.url) {
69 builds.push(buildInfo);
74 // Sort descending by revision.
75 builds.sort(function(a, b) { return b.revision - a.revision; });
76 self._didLoadRecentBuildsCallback(builds);
80 _buildbotBaseURL: "http://build.webkit.org/",