|
| 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 | +}); |
0 commit comments