Skip to content

Commit

Permalink
tools: generate authors list automatically
Browse files Browse the repository at this point in the history
* Add new `update-authors.js` tool that traverses commit history using
  `git log` and creates authors list.

* Decouple common functions into a module shared between tools.

* Add `.mailmap` file.  This file is automatically parsed by Git so that
  `git log --format='%aN <%aE>'` won't show duplicate entries in case
  something was committed with misconfigured Git.  E.g., without this
  file @tshemsedinov appears twice in the list, as Timur Shemsedinov
  and as tshemsedinov, but with mailmap applied Git automatically
  coalesces these entries to use the full name only.  This file now
  includes the active collaborators (@tshemsedinov for a reason and
  @aqrln and @belochub just in case), proper names and emails of
  contributors who committed with invalid ones should be placed here.

PR-URL: metarhia/jstp#88
  • Loading branch information
aqrln authored and belochub committed Jul 21, 2018
1 parent b85b5a8 commit ac768e2
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Timur Shemsedinov <timur.shemsedinov@gmail.com>
Alexey Orlenko <eaglexrlnk@gmail.com>
Mykola Bilochub <nbelochub@gmail.com>
27 changes: 27 additions & 0 deletions tools/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Common utilities used by tools
'use strict';

const childProcess = require('child_process');
const fs = require('fs');

const common = {};
module.exports = common;

common.getCommandOutput = (cmd) => {
const exec = common.promisify(childProcess.exec);
return exec(cmd).then((stdout, stderr) => {
if (stderr) console.error(stderr);
return stdout;
});
};

common.promisify = (fn) => (...args) => (
new Promise((resolve, reject) => {
fn(...args, (error, ...result) => {
if (error) reject(error);
else resolve(...result);
});
})
);

common.writeFile = common.promisify(fs.writeFile);
22 changes: 22 additions & 0 deletions tools/update-authors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

'use strict';

const path = require('path');
const { getCommandOutput, writeFile } = require('./common');

const AUTHORS_PATH = path.resolve(__dirname, '..', 'AUTHORS');

getCommandOutput('git log --reverse --format="%aN <%aE>"').then((out) => {
const authors = [];
for (const author of out.split('\n')) {
if (!authors.includes(author)) {
authors.push(author);
}
}
return writeFile(AUTHORS_PATH, authors.join('\n'));
}).catch((error) => {
const message = error.stack || error.toString();
console.error(message);
process.exit(1);
});

0 comments on commit ac768e2

Please sign in to comment.