BuildRequest should have a method to fetch all in-progress and pending requests for...
[WebKit-https.git] / Websites / perf.webkit.org / public / v3 / models / build-request.js
1 'use strict';
2
3 class BuildRequest extends DataModelObject {
4
5     constructor(id, object)
6     {
7         super(id, object);
8         this._testGroupId = object.testGroupId;
9         console.assert(!object.testGroup || object.testGroup instanceof TestGroup);
10         this._testGroup = object.testGroup;
11         if (this._testGroup)
12             this._testGroup.addBuildRequest(this);
13         this._order = object.order;
14         console.assert(object.rootSet instanceof RootSet);
15         this._rootSet = object.rootSet;
16         this._status = object.status;
17         this._statusUrl = object.url;
18         this._buildId = object.build;
19         this._result = null;
20     }
21
22     updateSingleton(object)
23     {
24         console.assert(this._testGroup == object.testGroup);
25         console.assert(this._order == object.order);
26         console.assert(this._rootSet == object.rootSet);
27         this._status = object.status;
28         this._statusUrl = object.url;
29         this._buildId = object.build;
30     }
31
32     testGroupId() { return this._testGroupId; }
33     testGroup() { return this._testGroup; }
34     order() { return this._order; }
35     rootSet() { return this._rootSet; }
36
37     hasFinished() { return this._status == 'failed' || this._status == 'completed' || this._status == 'canceled'; }
38     hasStarted() { return this._status != 'pending'; }
39     isPending() { return this._status == 'pending'; }
40     statusLabel()
41     {
42         switch (this._status) {
43         case 'pending':
44             return 'Waiting to be scheduled';
45         case 'scheduled':
46             return 'Scheduled';
47         case 'running':
48             return 'Running';
49         case 'failed':
50             return 'Failed';
51         case 'completed':
52             return 'Completed';
53         case 'canceled':
54             return 'Canceled';
55         }
56     }
57     statusUrl() { return this._statusUrl; }
58
59     buildId() { return this._buildId; }
60
61     result() { return this._result; }
62     setResult(result)
63     {
64         this._result = result;
65         this._testGroup.didSetResult(this);
66     }
67
68     static fetchForTriggerable(triggerable)
69     {
70         return RemoteAPI.getJSONWithStatus('/api/build-requests/' + triggerable).then(function (data) {
71             return BuildRequest.constructBuildRequestsFromData(data);
72         });
73     }
74
75     static constructBuildRequestsFromData(data)
76     {
77         var rootIdMap = {};
78         for (var root of data['roots']) {
79             rootIdMap[root.id] = root;
80             root.repository = Repository.findById(root.repository);
81         }
82
83         var rootSets = data['rootSets'].map(function (row) {
84             row.roots = row.roots.map(function (rootId) { return rootIdMap[rootId]; });
85             return RootSet.ensureSingleton(row.id, row);
86         });
87
88         return data['buildRequests'].map(function (rawData) {
89             rawData.platform = Platform.findById(rawData.platform);
90             rawData.test = Test.findById(rawData.test);
91             rawData.testGroupId = rawData.testGroup;
92             rawData.testGroup = TestGroup.findById(rawData.testGroup);
93             rawData.rootSet = RootSet.findById(rawData.rootSet);
94             return BuildRequest.ensureSingleton(rawData.id, rawData);
95         });
96     }
97 }
98
99 if (typeof module != 'undefined')
100     module.exports.BuildRequest = BuildRequest;