Add the support for scheduling a A/B testing with a patch.
[WebKit-https.git] / Websites / perf.webkit.org / public / v3 / models / manifest.js
1 'use strict';
2
3 class Manifest {
4
5     static fetch()
6     {
7         return RemoteAPI.getJSON('/data/manifest.json').catch(function () {
8             return RemoteAPI.getJSON('/api/manifest/');
9         }).then(this._didFetchManifest.bind(this));
10     }
11
12     static _didFetchManifest(rawResponse)
13     {
14         Instrumentation.startMeasuringTime('Manifest', '_didFetchManifest');
15
16         const tests = [];
17         const testParentMap = {};
18         for (let testId in rawResponse.tests)
19             tests.push(new Test(testId, rawResponse.tests[testId]));
20
21         function buildObjectsFromIdMap(idMap, constructor, resolver) {
22             for (let id in idMap) {
23                 if (resolver)
24                     resolver(idMap[id]);
25                 new constructor(id, idMap[id]);
26             }
27         }
28
29         buildObjectsFromIdMap(rawResponse.metrics, Metric, (raw) => {
30             raw.test = Test.findById(raw.test);
31         });
32
33         buildObjectsFromIdMap(rawResponse.all, Platform, (raw) => {
34             raw.lastModifiedByMetric = {};
35             raw.lastModified.forEach((lastModified, index) => {
36                 raw.lastModifiedByMetric[raw.metrics[index]] = lastModified;
37             });
38             raw.metrics = raw.metrics.map((id) => { return Metric.findById(id); });
39         });
40         buildObjectsFromIdMap(rawResponse.builders, Builder);
41         buildObjectsFromIdMap(rawResponse.repositories, Repository);
42         buildObjectsFromIdMap(rawResponse.bugTrackers, BugTracker, (raw) => {
43             if (raw.repositories)
44                 raw.repositories = raw.repositories.map((id) => { return Repository.findById(id); });
45         });
46         buildObjectsFromIdMap(rawResponse.triggerables, Triggerable, (raw) => {
47             raw.acceptedRepositories = raw.acceptedRepositories.map((repositoryId) => {
48                 return Repository.findById(repositoryId);
49             });
50             raw.repositoryGroups = raw.repositoryGroups.map((group) => {
51                 group.repositories = group.repositories.map((entry) => {
52                     return {repository: Repository.findById(entry.repository), acceptsPatch: entry.acceptsPatch};
53                 });
54                 return TriggerableRepositoryGroup.ensureSingleton(group.id, group);
55             });
56             raw.configurations = raw.configurations.map((configuration) => {
57                 const [testId, platformId] = configuration;
58                 return {test: Test.findById(testId), platform: Platform.findById(platformId)};
59             });
60         });
61
62         if (typeof(UploadedFile) != 'undefined')
63             UploadedFile.fileUploadSizeLimit = rawResponse.fileUploadSizeLimit || 0;
64
65         Instrumentation.endMeasuringTime('Manifest', '_didFetchManifest');
66
67         return {
68             siteTitle: rawResponse.siteTitle,
69             dashboards: rawResponse.dashboards, // FIXME: Add an abstraction around dashboards.
70             summaryPages: rawResponse.summaryPages,
71         }
72     }
73 }
74
75 if (typeof module != 'undefined')
76     module.exports.Manifest = Manifest;