forked from web-platform-tests/wpt.fyi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct-info.js
174 lines (160 loc) · 4.53 KB
/
product-info.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**
* Copyright 2018 The WPT Dashboard Project. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
const DisplayNames = (() => {
let m = new Map();
['chrome', 'chrome-experimental'].forEach(n => m.set(n, 'Chrome'));
['edge', 'edge-experimental'].forEach(n => m.set(n, 'Edge'));
['firefox', 'firefox-experimental'].forEach(n => m.set(n, 'Firefox'));
['safari', 'safari-experimental'].forEach(n => m.set(n, 'Safari'));
m.set('uc', 'UC Browser');
m.set('android', 'Android');
m.set('linux', 'Linux');
m.set('macos', 'macOS');
m.set('windows', 'Windows');
// Channels
m.set('stable', 'Stable');
m.set('beta', 'Beta');
m.set('experimental', 'Experimental');
m.set('dev', 'Dev'); // Chrome
m.set('preview', 'Technology Preview'); // Safari
m.set('nightly', 'Nightly'); // Firefox
// Sources
m.set('azure', 'Azure Pipelines');
m.set('buildbot', 'Buildbot');
m.set('msedge', 'MS Edge');
m.set('taskcluster', 'Taskcluster');
return m;
})();
const versionPatterns = Object.freeze({
Major: /(\d+)/,
MajorAndMinor: /(\d+\.\d+)/,
});
const DefaultBrowserNames = Object.freeze(['chrome', 'edge', 'firefox', 'safari']);
const DefaultProductSpecs = DefaultBrowserNames;
const DefaultProducts = DefaultProductSpecs.map(p => Object.freeze(parseProductSpec(p)));
const CommitTypes = new Set(['pr_head', 'master']);
const Channels = new Set(['stable', 'beta', 'experimental']);
const Sources = new Set(['buildbot', 'taskcluster', 'msedge', 'azure']);
const SemanticLabels = [
{ property: '_channel', values: Channels },
{ property: '_source', values: Sources },
];
function parseProductSpec(spec) {
// @sha (optional)
let revision = '';
const atIndex = spec.indexOf('@');
if (atIndex > 0) {
revision = spec.substr(atIndex + 1);
spec = spec.substr(0, atIndex);
}
// [foo,bar] labels syntax (optional)
let labels = [];
const arrayIndex = spec.indexOf('[');
if (arrayIndex > 0) {
let labelsStr = spec.substr(arrayIndex + 1);
if (labelsStr[labelsStr.length - 1] !== ']') {
throw 'Expected closing bracket';
}
const seenLabels = new Set();
labelsStr = labelsStr.substr(0, labelsStr.length - 1);
for (const label of labelsStr.split(',')) {
if (!seenLabels.has(label)) {
seenLabels.add(label);
labels.push(label);
}
}
spec = spec.substr(0, arrayIndex);
}
// product
const product = parseProduct(spec);
product.revision = revision;
product.labels = labels;
return product;
}
function parseProduct(name) {
// -version (optional)
let version;
const dashIndex = name.indexOf('-');
if (dashIndex > 0) {
version = name.substr(dashIndex + 1);
name = name.substr(0, dashIndex);
}
return {
browser_name: name,
browser_version: version,
};
}
// eslint-disable-next-line no-unused-vars
const ProductInfo = (superClass) => class extends superClass {
static get properties() {
return {
};
}
displayName(name) {
return DisplayNames.get(name) || name;
}
displayLabels(labels) {
if (labels && labels instanceof Array) {
return labels.join(', ');
}
return '';
}
minorIsSignificant(browserName) {
return browserName === 'safari';
}
/**
* Truncate a software version identifier to include only the most
* salient information for the specified browser.
*/
shortVersion(browserName, browserVersion) {
const pattern = this.minorIsSignificant(browserName)
? versionPatterns.MajorAndMinor
: versionPatterns.Major;
const match = pattern.exec(browserVersion);
if (!match) {
return browserVersion;
}
return match[1];
}
parseProductSpec(spec) {
return parseProductSpec(spec);
}
parseProduct(name) {
return parseProduct(name);
}
getSpec(product) {
let spec = product.browser_name;
if (product.browser_version) {
spec += `-${product.browser_version}`;
}
if (product.labels && product.labels.length) {
spec += `[${product.labels.join(',')}]`;
}
if (product.revision && !this.computeIsLatest(product.revision)) {
spec += `@${product.revision}`;
}
return spec;
}
computeIsLatest(sha) {
if (Array.isArray(sha)) {
return !sha.length || sha.length === 1 && this.computeIsLatest(sha[0]);
}
return !sha || sha === 'latest';
}
};
export {
DisplayNames,
DefaultBrowserNames,
DefaultProductSpecs,
DefaultProducts,
CommitTypes,
Channels,
Sources,
SemanticLabels,
ProductInfo,
parseProductSpec,
parseProduct,
};