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: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Anna Henningsen 2018-09-09 13:07:52 +02:00
parent df7ebfab4e
commit 175a88f094
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 50 additions and 22 deletions

50
tools/update-authors.js Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env node
// Usage: tools/update-author.js [--dry]
// Passing --dry will redirect output to stdout rather than write to 'AUTHORS'.
'use strict';
const { spawn } = require('child_process');
const fs = require('fs');
const readline = require('readline');
const log = spawn(
'git',
// Inspect author name/email and body.
['log', '--reverse', '--format=Author: %aN <%aE>\n%b'], {
stdio: ['inherit', 'pipe', 'inherit']
});
const rl = readline.createInterface({ input: log.stdout });
let output;
if (process.argv.includes('--dry'))
output = process.stdout;
else
output = fs.createWriteStream('AUTHORS');
output.write('# Authors ordered by first contribution.\n\n');
const seen = new Set();
// Support regular git author metadata, as well as `Author:` and
// `Co-authored-by:` in the message body. Both have been used in the past
// to indicate multiple authors per commit, with the latter standardized
// by GitHub now.
const authorRe =
/(^Author:|^Co-authored-by:)\s+(?<author>[^<]+)\s+(?<email><[^>]+>)/i;
rl.on('line', (line) => {
const match = line.match(authorRe);
if (!match) return;
const { author, email } = match.groups;
if (seen.has(email) ||
/@chromium\.org/.test(email) ||
email === '<erik.corry@gmail.com>') {
return;
}
seen.add(email);
output.write(`${author} ${email}\n`);
});
rl.on('close', () => {
output.end('\n# Generated by tools/update-authors.js\n');
});

View File

@ -1,22 +0,0 @@
#!/bin/sh
git log --reverse --format='%aN <%aE>' | perl -we '
BEGIN {
%seen = (), @authors = ();
}
while (<>) {
next if $seen{$_};
next if /\@chromium.org/;
next if /<erik.corry\@gmail.com>/;
$seen{$_} = push @authors, $_;
}
END {
print "# Authors ordered by first contribution.\n";
print "\n", @authors, "\n";
print "# Generated by tools/update-authors.sh\n";
}
' > AUTHORS