Update syncing script to be able to build binary for commit set with owned commits.
[WebKit.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.sortByNamePreferringOnesWithURL(object.repositories.map((item) => item.repository));
63         this._patchAcceptingSet = new Set(object.repositories.filter((item) => item.acceptsPatch).map((item) => item.repository));
64     }
65
66     accepts(commitSet)
67     {
68         const commitSetRepositories = commitSet.topLevelRepositories();
69         if (this._repositories.length != commitSetRepositories.length)
70             return false;
71         for (let i = 0; i < this._repositories.length; i++) {
72             const currentRepository = this._repositories[i];
73             if (currentRepository != commitSetRepositories[i])
74                 return false;
75             if (commitSet.patchForRepository(currentRepository) && !this._patchAcceptingSet.has(currentRepository))
76                 return false;
77         }
78         if (commitSet.customRoots().length && !this._acceptsCustomRoots)
79             return false;
80         return true;
81     }
82
83     acceptsPatchForRepository(repository)
84     {
85         return this._patchAcceptingSet.has(repository);
86     }
87
88     description() { return this._description || this.name(); }
89     acceptsCustomRoots() { return this._acceptsCustomRoots; }
90     repositories() { return this._repositories; }
91
92     static sortByNamePreferringSmallerRepositories(groupList)
93     {
94         return groupList.sort((a, b) => {
95             if (a.repositories().length < b.repositories().length)
96                 return -1;
97             else if (a.repositories().length > b.repositories().length)
98                 return 1;
99             if (a.name() < b.name())
100                 return -1;
101             else if (a.name() > b.name())
102                 return 1;
103             return 0;
104         });
105     }
106 }
107
108 if (typeof module != 'undefined') {
109     module.exports.Triggerable = Triggerable;
110     module.exports.TriggerableRepositoryGroup = TriggerableRepositoryGroup;
111 }
112