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: #88
  • Loading branch information
aqrln committed Mar 13, 2017
1 parent 9edd03f commit ebf9e2d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 22 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);
24 changes: 2 additions & 22 deletions tools/prepare-release.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

'use strict';

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

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

const commandName = path.relative('.', __filename);
const help = `\
This tool allows to filter the result of
Expand Down Expand Up @@ -83,14 +83,6 @@ getCommandOutput('git cherry ' + branch).then((cherryOut) => {
process.exit(1);
});

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

function getMetadata(commitHash) {
const command = 'git log --format="%aN%n%B" -n 1 ' + commitHash;
return getCommandOutput(command).then((output) => {
Expand Down Expand Up @@ -188,17 +180,6 @@ function getStreamData(stream, callback) {
stream.on('error', callback);
}

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

function processCommits(commits) {
commits = filterCommits(commits, maxLevel);

Expand Down Expand Up @@ -233,7 +214,6 @@ function processCommits(commits) {

script += '\n';

const writeFile = promisify(fs.writeFile);
return Promise.all([
writeFile(`${branch}-apply-commits.sh`, script),
writeFile(`${branch}-commits.md`, changelog)
Expand Down
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 ebf9e2d

Please sign in to comment.