Skip to content

Commit b2abeff

Browse files
addaleaxtargos
authored andcommitted
tools: implement update-authors in JS
Replace the previous Perl script with a Node.js variant that explicitly supports `Author:` and, in particular, GitHub’s standard `Co-authored-by:` metadata tags. PR-URL: #22771 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matheus Marchini <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent a96a846 commit b2abeff

File tree

2 files changed

+50
-22
lines changed

2 files changed

+50
-22
lines changed

tools/update-authors.js

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env node
2+
// Usage: tools/update-author.js [--dry]
3+
// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'.
4+
'use strict';
5+
const { spawn } = require('child_process');
6+
const fs = require('fs');
7+
const readline = require('readline');
8+
9+
const log = spawn(
10+
'git',
11+
// Inspect author name/email and body.
12+
['log', '--reverse', '--format=Author: %aN <%aE>\n%b'], {
13+
stdio: ['inherit', 'pipe', 'inherit']
14+
});
15+
const rl = readline.createInterface({ input: log.stdout });
16+
17+
let output;
18+
if (process.argv.includes('--dry'))
19+
output = process.stdout;
20+
else
21+
output = fs.createWriteStream('AUTHORS');
22+
23+
output.write('# Authors ordered by first contribution.\n\n');
24+
25+
const seen = new Set();
26+
27+
// Support regular git author metadata, as well as `Author:` and
28+
// `Co-authored-by:` in the message body. Both have been used in the past
29+
// to indicate multiple authors per commit, with the latter standardized
30+
// by GitHub now.
31+
const authorRe =
32+
/(^Author:|^Co-authored-by:)\s+(?<author>[^<]+)\s+(?<email><[^>]+>)/i;
33+
rl.on('line', (line) => {
34+
const match = line.match(authorRe);
35+
if (!match) return;
36+
37+
const { author, email } = match.groups;
38+
if (seen.has(email) ||
39+
/@chromium\.org/.test(email) ||
40+
email === '<[email protected]>') {
41+
return;
42+
}
43+
44+
seen.add(email);
45+
output.write(`${author} ${email}\n`);
46+
});
47+
48+
rl.on('close', () => {
49+
output.end('\n# Generated by tools/update-authors.js\n');
50+
});

tools/update-authors.sh

-22
This file was deleted.

0 commit comments

Comments
 (0)