From d8fd92ff889c7bf46bed9411781db3c3f6e47b21 Mon Sep 17 00:00:00 2001 From: Matheus Marchini Date: Tue, 1 Oct 2019 09:22:55 -0700 Subject: [PATCH] land: add non-interactive mode Non-interactive mode will try to land a Pull Request without asking any questions. This is meant to be used by scripts and CI landing tools. --- components/git/land.js | 5 +++++ lib/cli.js | 8 ++++++++ lib/landing_session.js | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/components/git/land.js b/components/git/land.js index 465ec7c0..21f9668c 100644 --- a/components/git/land.js +++ b/components/git/land.js @@ -38,6 +38,8 @@ function builder(yargs) { .options(landOptions).positional('prid', { describe: 'ID or URL of the Pull Request' }) + .boolean('non-interactive') + .defaults({ 'non-interactive': false }) .epilogue(epilogue) .example('git node land https://github.com/nodejs/node/pull/12344', 'Land https://github.com/nodejs/node/pull/12344 in the current directory') @@ -93,6 +95,9 @@ function handler(argv) { function land(state, argv) { const cli = new CLI(process.stderr); + if (argv['non-interactive']) { + cli.setNonInteractive(); + } const req = new Request(); const dir = process.cwd(); diff --git a/lib/cli.js b/lib/cli.js index 165771f8..7e5e3bc6 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -24,6 +24,7 @@ class CLI { this.spinner = ora({ stream: this.stream }); this.SPINNER_STATUS = SPINNER_STATUS; this.figureIndent = ' '; + this.nonInteractive = false; } get eolIndent() { @@ -36,6 +37,9 @@ class CLI { async prompt(question, defaultAnswer = true) { this.separator(); + if (this.nonInteractive) { + return defaultAnswer; + } const { answer } = await inquirer.prompt([{ type: 'confirm', name: 'answer', @@ -45,6 +49,10 @@ class CLI { return answer; } + setNonInteractive() { + this.nonInteractive = true; + } + startSpinner(text) { this.spinner.text = text; this.spinner.start(); diff --git a/lib/landing_session.js b/lib/landing_session.js index ef59affd..dcd34d92 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -20,7 +20,7 @@ class LandingSession extends Session { this.startLanding(); const status = metadata.status ? 'should be ready' : 'is not ready'; const shouldContinue = await cli.prompt( - `This PR ${status} to land, do you want to continue?`); + `This PR ${status} to land, do you want to continue?`, metadata.status); if (!shouldContinue) { return this.abort(); }