feat(dev-infra): integrate merge script into ng-dev cli (#37138)

Integrates the merge script into the `ng-dev` CLI. The goal is that
caretakers can run the same command across repositories to merge a pull
request. The command is as followed: `yarn ng-dev pr merge <number>`.

PR Close #37138
This commit is contained in:
Paul Gschwendtner
2020-05-15 17:21:01 +02:00
committed by Kara Erickson
parent 318e9372c9
commit 8a3493af47
16 changed files with 237 additions and 97 deletions

View File

@ -7,39 +7,20 @@
*/
import * as yargs from 'yargs';
import {discoverNewConflictsForPr} from './discover-new-conflicts';
/** A Date object 30 days ago. */
const THIRTY_DAYS_AGO = (() => {
const date = new Date();
// Set the hours, minutes and seconds to 0 to only consider date.
date.setHours(0, 0, 0, 0);
// Set the date to 30 days in the past.
date.setDate(date.getDate() - 30);
return date;
})();
import {buildDiscoverNewConflictsCommand, handleDiscoverNewConflictsCommand} from './discover-new-conflicts/cli';
import {buildMergeCommand, handleMergeCommand} from './merge/cli';
/** Build the parser for the pr commands. */
/** Build the parser for pull request commands. */
export function buildPrParser(localYargs: yargs.Argv) {
return localYargs.help().strict().demandCommand().command(
'discover-new-conflicts <pr>',
'Check if a pending PR causes new conflicts for other pending PRs',
args => {
return args.option('date', {
description: 'Only consider PRs updated since provided date',
defaultDescription: '30 days ago',
coerce: Date.parse,
default: THIRTY_DAYS_AGO,
});
},
({pr, date}) => {
// If a provided date is not able to be parsed, yargs provides it as NaN.
if (isNaN(date)) {
console.error('Unable to parse the value provided via --date flag');
process.exit(1);
}
discoverNewConflictsForPr(pr, date);
});
return localYargs.help()
.strict()
.demandCommand()
.command('merge <pr-number>', 'Merge pull requests', buildMergeCommand, handleMergeCommand)
.command(
'discover-new-conflicts <pr-number>',
'Check if a pending PR causes new conflicts for other pending PRs',
buildDiscoverNewConflictsCommand, handleDiscoverNewConflictsCommand)
}
if (require.main === module) {