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 <targos@protonmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent a96a846 commit b2abeff

2 files changed

Lines changed: 50 additions & 22 deletions

File tree

‎tools/update-authors.js‎

Lines changed: 50 additions & 0 deletions
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+
constfs=require('fs');
7+
constreadline=require('readline');
8+
9+
constlog=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+
constrl=readline.createInterface({input: log.stdout});
16+
17+
letoutput;
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+
constseen=newSet();
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+
constauthorRe=
32+
/(^Author:|^Co-authored-by:)\s+(?<author>[^<]+)\s+(?<email><[^>]+>)/i;
33+
rl.on('line',(line)=>{
34+
constmatch=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==='<erik.corry@gmail.com>'){
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‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)