c6f81e282c16d09c2e421075b1f45682ea0354c3
[WebKit-https.git] / Websites / perf.webkit.org / public / v3 / models / triggerable.js
1 class Triggerable extends LabeledObject {
2
3     constructor(id, object)
4     {
5         super(id, object);
6         this._name = object.name;
7         this._isDisabled = !!object.isDisabled;
8         this._acceptedRepositories = object.acceptedRepositories;
9         this._repositoryGroups = object.repositoryGroups;
10         this._configurationList = object.configurations;
11         this._acceptedTests = new Set;
12
13         const configurationMap = this.ensureNamedStaticMap('testConfigurations');
14         for (const config of object.configurations) {
15             const key = `${config.test.id()}-${config.platform.id()}`;
16             this._acceptedTests.add(config.test);
17             console.assert(!(key in configurationMap));
18             configurationMap[key] = this;
19         }
20     }
21
22     name() { return this._name; }
23     isDisabled() { return this._isDisabled; }
24     repositoryGroups() { return this._repositoryGroups; }
25
26     acceptsTest(test) { return this._acceptedTests.has(test); }
27
28     static findByTestConfiguration(test, platform)
29     {
30         let configurationMap = this.ensureNamedStaticMap('testConfigurations');
31         if (!configurationMap)
32             return null;
33         for (; test; test = test.parentTest()) {
34             const key = `${test.id()}-${platform.id()}`;
35             if (key in configurationMap)
36                 return configurationMap[key];
37         }
38         return null;
39     }
40
41     static triggerablePlatformsForTests(tests)
42     {
43         console.assert(tests instanceof Array);
44         if (!tests.length)
45             return [];
46         return this.sortByName(Platform.all().filter((platform) => {
47             return tests.every((test) => {
48                 const triggerable = Triggerable.findByTestConfiguration(test, platform);
49                 return triggerable && !triggerable.isDisabled();
50             });
51         }));
52     }
53 }
54
55 class TriggerableRepositoryGroup extends LabeledObject {
56
57     constructor(id, object)
58     {
59         super(id, object);
60         this._description = object.description;
61         this._acceptsCustomRoots = !!object.acceptsCustomRoots;
62         this._repositories = Repository.sortByName(object.repositories);
63     }
64
65     accepts(commitSet)
66     {
67         const commitSetRepositories = Repository.sortByName(commitSet.repositories());
68         if (this._repositories.length != commitSetRepositories.length)
69             return false;
70         for (let i = 0; i < this._repositories.length; i++) {
71             if (this._repositories[i] != commitSetRepositories[i])
72                 return false;
73         }
74         return true;
75     }
76
77     description() { return this._description || this.name(); }
78     acceptsCustomRoots() { return this._acceptsCustomRoots; }
79     repositories() { return this._repositories; }
80
81     static sortByNamePreferringSmallerRepositories(groupList)
82     {
83         return groupList.sort((a, b) => {
84             if (a.repositories().length < b.repositories().length)
85                 return -1;
86             else if (a.repositories().length > b.repositories().length)
87                 return 1;
88             if (a.name() < b.name())
89                 return -1;
90             else if (a.name() > b.name())
91                 return 1;
92             return 0;
93         });
94     }
95 }
96
97 if (typeof module != 'undefined') {
98     module.exports.Triggerable = Triggerable;
99     module.exports.TriggerableRepositoryGroup = TriggerableRepositoryGroup;
100 }
101