Skip to content

Commit

Permalink
land: add non-interactive mode
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mmarchini committed Oct 1, 2019
1 parent 72fc10a commit d8fd92f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions components/git/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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();

Expand Down
8 changes: 8 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class CLI {
this.spinner = ora({ stream: this.stream });
this.SPINNER_STATUS = SPINNER_STATUS;
this.figureIndent = ' ';
this.nonInteractive = false;
}

get eolIndent() {
Expand All @@ -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',
Expand All @@ -45,6 +49,10 @@ class CLI {
return answer;
}

setNonInteractive() {
this.nonInteractive = true;
}

startSpinner(text) {
this.spinner.text = text;
this.spinner.start();
Expand Down
2 changes: 1 addition & 1 deletion lib/landing_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit d8fd92f

Please sign in to comment.