From b2abeff43c8ed3cab48849f1104a25bc088c439b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sun, 9 Sep 2018 13:07:52 +0200 Subject: [PATCH] tools: implement update-authors in JS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Daniel Bevenius Reviewed-By: Tobias Nießen Reviewed-By: Luigi Pinca Reviewed-By: Matheus Marchini Reviewed-By: Richard Lau Reviewed-By: Ruben Bridgewater Reviewed-By: Matteo Collina Reviewed-By: James M Snell --- tools/update-authors.js | 50 +++++++++++++++++++++++++++++++++++++++++ tools/update-authors.sh | 22 ------------------ 2 files changed, 50 insertions(+), 22 deletions(-) create mode 100755 tools/update-authors.js delete mode 100755 tools/update-authors.sh diff --git a/tools/update-authors.js b/tools/update-authors.js new file mode 100755 index 00000000000000..1c48eaec85c823 --- /dev/null +++ b/tools/update-authors.js @@ -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+(?[^<]+)\s+(?<[^>]+>)/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 === '') { + return; + } + + seen.add(email); + output.write(`${author} ${email}\n`); +}); + +rl.on('close', () => { + output.end('\n# Generated by tools/update-authors.js\n'); +}); diff --git a/tools/update-authors.sh b/tools/update-authors.sh deleted file mode 100755 index d07d9c9ff73c43..00000000000000 --- a/tools/update-authors.sh +++ /dev/null @@ -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 //; - $seen{$_} = push @authors, $_; -} - -END { - print "# Authors ordered by first contribution.\n"; - print "\n", @authors, "\n"; - print "# Generated by tools/update-authors.sh\n"; -} - -' > AUTHORS