From cbcf4b0bd8713a1fb0cd2e5a7c5f657c424ee4f8 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 14 Oct 2021 15:39:04 +0200 Subject: [PATCH 1/2] feat(cli): prompt user when landing PR with several commits And add an option to abort the session if trying to land more than one commit. Refs: https://github.com/nodejs/node/issues/40436 --- components/git/land.js | 6 ++++++ lib/landing_session.js | 26 +++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/components/git/land.js b/components/git/land.js index f80cf857..dff93c2e 100644 --- a/components/git/land.js +++ b/components/git/land.js @@ -46,6 +46,12 @@ const landActions = { 'other commit messages', default: false, type: 'boolean' + }, + oneCommitMax: { + describe: 'When run in conjunction with the --yes and --autorebase ' + + 'options, will abort the session if trying to land more than one commit', + default: false, + type: 'boolean' } }; diff --git a/lib/landing_session.js b/lib/landing_session.js index 88d4c7fe..baa3d927 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -22,14 +22,17 @@ const LINT_RESULTS = { }; class LandingSession extends Session { - constructor(cli, req, dir, - { prid, backport, lint, autorebase, fixupAll, checkCI } = {}) { + constructor(cli, req, dir, { + prid, backport, lint, autorebase, fixupAll, + checkCI, oneCommitMax + } = {}) { super(cli, dir, prid); this.req = req; this.backport = backport; this.lint = lint; this.autorebase = autorebase; this.fixupAll = fixupAll; + this.oneCommitMax = oneCommitMax; this.expectedCommitShas = []; this.checkCI = !!checkCI; } @@ -40,6 +43,7 @@ class LandingSession extends Session { args.lint = this.lint; args.autorebase = this.autorebase; args.fixupAll = this.fixupAll; + args.oneCommitMax = this.oneCommitMax; return args; } @@ -349,7 +353,9 @@ class LandingSession extends Session { } async final() { - const { cli, owner, repo, upstream, branch, prid } = this; + const { + cli, owner, repo, upstream, branch, prid, oneCommitMax + } = this; // Check that git rebase/am has been completed. if (!this.readyToFinal()) { @@ -360,6 +366,20 @@ class LandingSession extends Session { }; const stray = this.getStrayCommits(); + if (stray.length > 1) { + const forceLand = await cli.prompt( + 'There are more than one commit in the PR. ' + + 'Do you still want to land it?', + { defaultAnswer: !oneCommitMax }); + + if (!forceLand) { + cli.info( + 'Use --fixupAll option, squash the PR manually or land the PR from ' + + 'the command line.' + ); + process.exit(1); + } + } const strayVerbose = this.getStrayCommits(true); const validateCommand = path.join( __dirname, From 6b173fbc90bae96dafa04f4355a01762ca735949 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 27 Oct 2021 16:57:58 +0200 Subject: [PATCH 2/2] fixup! feat(cli): prompt user when landing PR with several commits MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michaƫl Zasso --- lib/landing_session.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/landing_session.js b/lib/landing_session.js index baa3d927..8d4ba039 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -368,7 +368,7 @@ class LandingSession extends Session { const stray = this.getStrayCommits(); if (stray.length > 1) { const forceLand = await cli.prompt( - 'There are more than one commit in the PR. ' + + 'There is more than one commit in the PR. ' + 'Do you still want to land it?', { defaultAnswer: !oneCommitMax });