-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathcheck-form.js
282 lines (247 loc) · 8.11 KB
/
check-form.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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env node
const { execSync } = require('child_process');
// web URL: `https://docs.google.com/spreadsheets/d/${sheetID}/edit`
const sheetID = '1if5bU0aV5MJ27GGKnRzyAozeKP-ILXYl5r3dzvkGFmg';
const {
GOOGLE_API_KEY: key, // TC39 API key for google sheets
GH_TOKEN
} = process.env;
if (!GH_TOKEN) {
throw 'GH_TOKEN env var required';
}
if (!key) {
throw 'GOOGLE_API_KEY env var required';
}
const sheetData = `https://sheets.googleapis.com/v4/spreadsheets/${sheetID}/values/Sheet1!A2:A?key=${key}`;
const { values, positionals } = require('util').parseArgs({
allowPositionals: true,
strict: true,
});
if (positionals.length < 1 || positionals.length > 2) {
throw 'usage: node check-form.js <slug> [ref]';
}
const [slug, ref = 'HEAD'] = positionals;
console.debug({ slug, ref });
if (!slug || !ref) {
throw 'args required: slug, ref';
}
const sha = String(execSync(`git rev-parse ${ref}`)).trim();
const request = async (url, method = 'GET', postData) => {
// adapted from https://medium.com/@gevorggalstyan/how-to-promisify-node-js-http-https-requests-76a5a58ed90c
const lib = url.startsWith('https://') ? require('https') : require('http');
const [h, path] = url.split('://')[1].split('/');
const [host, port] = h.split(':');
const params = {
host,
port: port || url.startsWith('https://') ? 443 : 80,
method,
headers: {
Authorization: `token ${GH_TOKEN}`,
'User-Agent': 'curl/7.54.0'
}
};
return new Promise((resolve, reject) => {
const req = lib.request(url, params, res => {
if (res.statusCode < 200 || res.statusCode >= 300) {
return reject(new Error(`Status Code: ${res.statusCode}; ${url}`));
}
const data = [];
res.on('data', chunk => {
data.push(chunk);
});
res.on('end', () => resolve(String(Buffer.concat(data))));
});
req.on('error', reject);
if (postData) {
req.write(postData);
}
req.end();
});
};
const initial = '11db17a21add028b8d12930a8b047af1df2d3194'; // git rev-list --max-parents=0 HEAD
const perPage = 100;
const legacyCommitsWithUnknownAuthors = new Set([
'6e2f689b1bcecaf59f5e7c76e544443ffe4ed299',
'a103b287cd19bdc51c7a3d8d7c1431b1506a74e2',
'2527be4344c78e5ed56aef8e08463160f5bb2154',
'5c9f191c9e6ccfc909817510bf74fd64ea145ac4',
'8710d2b2a8906d0d41e90cfcb9f47573d8d573fb',
'0b89915d3ccbf372e8114d823688d74e7778bfdb',
'4374762005846b779d1cc4f03aeababe41af0e79',
'676dae0955b072a31b05eafdab17dfcd8f7b4975',
'2724be0f9aeb6265c60935334a3bdc293b2c4b4e',
'1c6fb24ef7b29558593ce6fd4310c3bc4fe67d82',
'dcc9584e642b55b8a99df91f2e80d065e3d2451c',
'daef7b05b2625caf06ab546acd6eb654e9777d16',
'eb0615ea028000d84f3d5dcd9d94a74558d3a206',
'50ec9b4195df6caf4da2352e0edb19024b515f2d',
'8d7995d6f7538534f2a54af4811c939ac8614676',
'1046a423adf3ea9c5460cdbdf3a9c156f52f1632',
'cdf5865b7da09cce276581f134349e24d2b6c199',
'b7d01876c19751e4c75d9910ce4fb2e0d1dc45fa',
'cc46cc38b9374d13f958cc6992daaec73d5fbecd',
'f424bf075fe582ed8acc36e8a420ee713a21561a', // https://github.com/tc39/ecma262/pull/3142
'bea8d0d682fcf2be2a29564bd2ae66ab9dcce21c', // https://github.com/tc39/ecma262/pull/612, user deleted their github
'329069469609d8f05ad64c328e2295c171050ce4', // https://github.com/tc39/ecma262/pull/3249, commit email doesn't point to the github user
'57f427b18bf7e629565ac2fcf2392ba7b7d0d8fb', // https://github.com/tc39/ecma262/pull/3127, user account deactivated
'aada40840dc152d4759b0e3353542e971db08ee7', // tutizaraz (signed) renamed their account to riwom -> dbarabashh
'57f427b18bf7e629565ac2fcf2392ba7b7d0d8fb', // https://github.com/tc39/ecma262/pull/3377, bojavou has not signed the form
]);
function getAuthorFromCommit(commitObj) {
if (!commitObj) {
return false;
}
const { author } = commitObj;
if (!author) {
return Symbol(commitObj.sha);
}
return author.login;
}
async function getAllCommits(page = 1) {
const commitsURL = `https://api.github.com/repos/${slug}/commits?anon=1&per_page=${perPage}&page=${page}&sha=${sha}`;
const commits = await request(commitsURL).then((json) => JSON.parse(json));
return [...new Set([].concat(
commits.filter(x => !legacyCommitsWithUnknownAuthors.has(x?.sha)).flatMap(x => getAuthorFromCommit(x) || []),
commits.length < perPage ? [] : await getAllCommits(page + 1),
))];
}
const authors = getAllCommits().then((authors) => {
const knowns = authors.filter(x => typeof x === 'string');
const unknowns = authors.filter(x => typeof x === 'symbol' && !legacyCommitsWithUnknownAuthors.has(x.description));
console.log(`Found ${knowns.length} authors: ${knowns.join(',')}\n`);
if (unknowns.length > 0) {
console.log(`${unknowns.length} commits have an unknown author: ${unknowns.map(x => x.description).join(',')}\n`);
}
if (legacyCommitsWithUnknownAuthors.size > 0) {
console.log(`${legacyCommitsWithUnknownAuthors.size} commits with an unknown author are legacy: ${[...legacyCommitsWithUnknownAuthors].join(',')}\n`);
}
if (unknowns.length > 0) {
throw unknowns;
}
return knowns;
});
const teamURL = (team) => `https://api.github.com/orgs/tc39/teams/${team}`;
function getMembers(teamID, page = 1) {
const memberURL = `https://api.github.com/teams/${teamID}/members?per_page=100&page=${page}`;
const data = request(memberURL).then((json) => JSON.parse(json));
return data.then((data) => {
if (data.length === 0) {
return data;
}
return getMembers(teamID, page + 1).then(nextPage => {
return data.concat(nextPage);
});
});
}
const aliases = new Map([
['bmeck', 'bfarias-godaddy'],
['PeterJensen', 'P-Jensen'].map(x => x.toLowerCase()),
]);
function handler(kind) {
return (data) => {
const names = new Set(data.map(x => x.login.toLowerCase()));
aliases.forEach((alias, main) => {
if (names.has(main)) {
names.add(alias);
}
});
console.log(`Found ${names.size} ${kind}: ${[...names].join(',')}\n`);
return names;
}
}
const delegates = request(teamURL('delegates')).then((json) => JSON.parse(json)).then(data => {
return getMembers(data.id);
}).then(handler('delegates'));
const emeriti = request(teamURL('emeriti')).then((json) => JSON.parse(json)).then(data => {
return getMembers(data.id);
}).then(handler('emeriti'));
const usernames = request(sheetData).then((json) => JSON.parse(json)).then(data => {
if (!Array.isArray(data.values)) {
throw 'invalid data';
}
const usernames = new Set(
data.values
.flat(1)
.map(x => x.replace(/^(https?:\/\/)?github\.com\//, '').replace(/^@/, '').toLowerCase())
.filter(x => /^[a-z0-9_-]{1,39}$/gi.test(x))
.sort((a, b) => a.localeCompare(b))
);
console.log(`Found ${usernames.size} usernames: ` + [...usernames].join(',') + '\n');
return usernames;
});
const exceptions = new Set([
'leebyron', // former FB delegate
'marjaholtta', // Google employee
'rossberg',
'arv',
'sideshowbarker', // Mozilla employee
'jswalden',
'GeorgNeis',
'natashenka', // Google employee
'IgorMinar', // former Google employee
].map(x => x.toLowerCase()));
// TODO: remove these as they sign the form
const legacy = new Set([
'pacokwon',
'himsngh',
'angleKH',
'ivan-pan',
'chrikrah',
'viktmv',
'bathos',
'johnnyrainbow',
'Kriyszig',
'Tomy8s',
'ahungry',
'divmain',
'RReverser',
'him2him2',
'jungshik',
'tmerr',
'v-stein',
'nathan',
'guimier',
'aweary',
'timoxley',
'thefourtheye',
'kdex',
'wwwillchen',
'jmm',
'alrra',
'prayagverma',
'UltCombo',
'ReadmeCritic',
'dslomov',
'DmitrySoshnikov',
'jsreeram',
'antony-jeong',
].map(x => x.toLowerCase()));
Promise.all([usernames, authors, delegates, emeriti]).then(([usernames, authors, delegates, emeriti]) => {
let legacyCount = legacy.size;
const missing = authors.filter(author => {
const a = author.toLowerCase();
const signed = usernames.has(a)
|| delegates.has(a)
|| emeriti.has(a)
|| exceptions.has(a);
if (legacy.has(a)) {
if (signed) {
legacyCount -= 1;
console.warn(`TODO: remove ${a} from legacy list`);
}
return false;
}
return !signed;
});
if (legacyCount > 0) {
console.info(`Legacy missing: ${legacyCount}`);
}
if (missing.length > 0) {
throw `Missing ${missing.length} authors: ${missing}`;
} else {
console.log('All authors have signed the form, or are delegates or emeriti!');
}
}).catch((e) => {
console.error(e);
process.exitCode = 1;
});