Skip to content

Commit

Permalink
build: add scripts to merge GitHub PRs (#20)
Browse files Browse the repository at this point in the history
PR Close #20
  • Loading branch information
sarunint committed Dec 12, 2017
1 parent 00be44e commit b90a68d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"main": "index.js",
"scripts": {
"test": "node ./scripts/checker.js",
"build-checker": "tsc -p ./tsconfig.json"
"build-checker": "tsc -p ./tsconfig.json",
"merge-pr": "node ./scripts/github/merge_pr.js"
},
"repository": {
"type": "git",
Expand Down
26 changes: 26 additions & 0 deletions scripts/github/github_closes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var msg = '';

if (require.main === module) {
process.stdin.setEncoding('utf8');

process.stdin.on('readable', () => {
const chunk = process.stdin.read();
if (chunk !== null) {
msg += chunk;
}
});

process.stdin.on('end', () => {
var argv = process.argv.slice(2);
console.log(rewriteMsg(msg, argv[0]));
});
}

function rewriteMsg(msg, prNo) {
var lines = msg.split(/\n/);
lines[0] += ' (#' + prNo + ')';
lines.push('PR Close #' + prNo);
return lines.join('\n');
}

exports.rewriteMsg = rewriteMsg;
22 changes: 22 additions & 0 deletions scripts/github/merge_pr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const run_command_1 = require("./run_command");
const path_1 = require("path");
const current = run_command_1.run('git rev-parse --abbrev-ref HEAD').trim();
const base = path_1.resolve(__dirname, '../..');
if (current !== 'master') {
console.log('Not currently on master');
process.exitCode = 1;
}
else {
if (process.argv.length !== 3) {
console.log('Merge GitHub PR into the master branch');
console.log();
console.log(`${process.argv[0]} ${process.argv[1]} PR_NUMBER`);
console.log();
}
else {
const prNumber = process.argv[2];
run_command_1.run(`git fetch upstream pull/${prNumber}/head:pr${prNumber}`);
run_command_1.run(`git filter-branch -f --msg-filter "${process.argv[0]} ${path_1.resolve(base, 'scripts/github/github_closes.js')} ${prNumber}" master..pr${prNumber}`);
run_command_1.run(`git cherry-pick master..pr${prNumber}`);
}
}
4 changes: 4 additions & 0 deletions scripts/github/run_command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const child_process_1 = require("child_process");
exports.run = (command) => {
return child_process_1.execSync(command).toString();
};

0 comments on commit b90a68d

Please sign in to comment.