diff --git a/package.json b/package.json index 0914da5fd..7778bc788 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/github/github_closes.js b/scripts/github/github_closes.js new file mode 100644 index 000000000..160b35da0 --- /dev/null +++ b/scripts/github/github_closes.js @@ -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; diff --git a/scripts/github/merge_pr.js b/scripts/github/merge_pr.js new file mode 100644 index 000000000..3a3617f2e --- /dev/null +++ b/scripts/github/merge_pr.js @@ -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}`); + } +} diff --git a/scripts/github/run_command.js b/scripts/github/run_command.js new file mode 100644 index 000000000..618c31642 --- /dev/null +++ b/scripts/github/run_command.js @@ -0,0 +1,4 @@ +const child_process_1 = require("child_process"); +exports.run = (command) => { + return child_process_1.execSync(command).toString(); +};