File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,13 @@ const landOptions = {
3030 abort : {
3131 describe : 'Abort the current landing session' ,
3232 type : 'boolean'
33+ } ,
34+ yes : {
35+ type : 'boolean' ,
36+ default : false ,
37+ describe : 'Assume "yes" as answer to all prompts and run ' +
38+ 'non-interactively. If an undesirable situation occurs, such as a pull ' +
39+ 'request or commit check fails, then git node land will abort.'
3340 }
3441} ;
3542
@@ -93,6 +100,9 @@ function handler(argv) {
93100
94101function land ( state , argv ) {
95102 const cli = new CLI ( process . stderr ) ;
103+ if ( argv . yes ) {
104+ cli . setAssumeYes ( ) ;
105+ }
96106 const req = new Request ( ) ;
97107 const dir = process . cwd ( ) ;
98108
Original file line number Diff line number Diff line change @@ -40,6 +40,11 @@ Options:
4040 --continue, -c Continue the landing session [boolean]
4141 --final Verify the landed PR and clean up [boolean]
4242 --abort Abort the current landing session [boolean]
43+ --yes Assume "yes" as answer to all prompts and run
44+ non-interactively. If an undesirable situation occurs, such as
45+ a pull request or commit check fails, then git node land will
46+ abort. [boolean] [default: false]
47+
4348
4449Examples:
4550 git node land 12344 Land https://github.com/nodejs/node/pull/12344 in
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ class CLI {
2424 this . spinner = ora ( { stream : this . stream } ) ;
2525 this . SPINNER_STATUS = SPINNER_STATUS ;
2626 this . figureIndent = ' ' ;
27+ this . assumeYes = false ;
2728 }
2829
2930 get eolIndent ( ) {
@@ -36,6 +37,9 @@ class CLI {
3637
3738 async prompt ( question , defaultAnswer = true ) {
3839 this . separator ( ) ;
40+ if ( this . assumeYes ) {
41+ return defaultAnswer ;
42+ }
3943 const { answer } = await inquirer . prompt ( [ {
4044 type : 'confirm' ,
4145 name : 'answer' ,
@@ -45,6 +49,10 @@ class CLI {
4549 return answer ;
4650 }
4751
52+ setAssumeYes ( ) {
53+ this . assumeYes = true ;
54+ }
55+
4856 startSpinner ( text ) {
4957 this . spinner . text = text ;
5058 this . spinner . start ( ) ;
Original file line number Diff line number Diff line change @@ -22,21 +22,27 @@ class LandingSession extends Session {
2222 const { cli } = this ;
2323 this . startLanding ( ) ;
2424 const status = metadata . status ? 'should be ready' : 'is not ready' ;
25+ // NOTE(mmarchini): default answer is yes. If --yes is given, we need to be
26+ // more careful though, and we change the default to the result of our
27+ // metadata check.
28+ const defaultAnswer = ! cli . assumeYes ? true : metadata . status ;
2529 const shouldContinue = await cli . prompt (
26- `This PR ${ status } to land, do you want to continue?` ) ;
30+ `This PR ${ status } to land, do you want to continue?` , defaultAnswer ) ;
2731 if ( ! shouldContinue ) {
28- return this . abort ( ) ;
32+ return this . abort ( false ) ;
2933 }
3034
3135 this . saveMetadata ( metadata ) ;
3236 this . startApplying ( ) ;
3337 return this . apply ( ) ;
3438 }
3539
36- async abort ( ) {
40+ async abort ( tryResetBranch = true ) {
3741 const { cli } = this ;
3842 this . cleanFiles ( ) ;
39- await this . tryResetBranch ( ) ;
43+ if ( tryResetBranch ) {
44+ await this . tryResetBranch ( ) ;
45+ }
4046 cli . ok ( `Aborted \`git node land\` session in ${ this . ncuDir } ` ) ;
4147 }
4248
Original file line number Diff line number Diff line change @@ -165,4 +165,24 @@ describe('cli', () => {
165165 } ) ;
166166 } ) ;
167167 } ) ;
168+
169+ describe ( 'prompt assume yes' , ( ) => {
170+ beforeEach ( ( ) => {
171+ stream = new LogStream ( ) ;
172+ cli = new CLI ( stream ) ;
173+ cli . setAssumeYes ( ) ;
174+ } ) ;
175+
176+ it ( 'should return true if no default is given' , async ( ) => {
177+ assert . strictEqual ( await cli . prompt ( 'Question?' ) , true ) ;
178+ } ) ;
179+
180+ it ( 'should return true if default is set to true' , async ( ) => {
181+ assert . strictEqual ( await cli . prompt ( 'Question?' , true ) , true ) ;
182+ } ) ;
183+
184+ it ( 'should return false if default is set to false' , async ( ) => {
185+ assert . strictEqual ( await cli . prompt ( 'Question?' , false ) , false ) ;
186+ } ) ;
187+ } ) ;
168188} ) ;
You can’t perform that action at this time.
0 commit comments