From bc7093ef68d3c0fa5e45110b67a695ac57dca6f6 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 4 Jun 2020 10:02:22 -0700 Subject: [PATCH 1/3] fix: lint during the landing process --- lib/landing_session.js | 57 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/lib/landing_session.js b/lib/landing_session.js index 20fc81b3..e2059999 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -1,6 +1,7 @@ 'use strict'; const path = require('path'); +const os = require('os'); const { getUnmarkedDeprecations, updateDeprecations @@ -130,8 +131,25 @@ class LandingSession extends Session { return command; } - async suggestAfterPatch(patch) { + async validateLint() { const { cli } = this; + + // The linter is currently only run on non-Windows platforms. + if (os.platform() === 'win32') { + return true; + } + + const linted = await runAsync('make', ['lint']); + if (!linted) { + cli.warn('There are lint errors in your patch. ' + + 'Please fix them before proceeding'); + } + return linted; + } + + async tryCompleteLanding(patch) { + const { cli } = this; + const subjects = patch.match(/Subject: \[PATCH.*?\].*/g); if (!subjects) { cli.warn('Cannot get number of commits in the patch. ' + @@ -154,6 +172,7 @@ class LandingSession extends Session { if (!canFinal) { return; } + return this.final(); } @@ -167,16 +186,36 @@ class LandingSession extends Session { async apply() { const { cli } = this; + + // Bail if another landing session is currently in progress. if (!this.isApplying()) { - cli.warn('This session can not proceed to apply patches, ' + - 'run `git node land --abort`'); + cli.warn('Landing session already in progress - ' + + 'to start a new one run `git node land --abort`'); return; } await this.tryResetBranch(); const patch = await this.downloadAndPatch(); + + const cleanLint = await this.validateLint(patch); + if (!cleanLint) { + const correctedLint = await cli.prompt('Corrected lint errors?'); + if (correctedLint) { + await runAsync('git', ['add', '.']); + + // Final message will be edited later - don't try to change it here. + await runAsync('git', ['commit', '--amend', '--no-edit']); + } else { + cli.info('Please fix lint errors and then run ' + + '`git node land --amend` followed by ' + + '`git node land --continue`.'); + process.exit(1); + } + } + this.startAmending(); - await this.suggestAfterPatch(patch); + + await this.tryCompleteLanding(patch); } async amend() { @@ -239,7 +278,8 @@ class LandingSession extends Session { async final() { const { cli, owner, repo, upstream, branch, prid } = this; - if (!this.readyToFinal()) { // check git rebase/am has been done + // Check that git rebase/am has been completed. + if (!this.readyToFinal()) { cli.warn('Not yet ready to final'); cli.log('A git rebase/am is in progress.' + ' Please complete it before running git node land --final'); @@ -301,13 +341,14 @@ class LandingSession extends Session { return this.amend(); } if (this.isApplying()) { - // We are resolving conflict + // We're still resolving conflicts. if (this.amInProgress()) { cli.log('Looks like you are resolving a `git am` conflict'); cli.log('Please run `git status` for help'); - } else { // The conflict has been resolved + } else { + // Conflicts has been resolved - amend. this.startAmending(); - return this.suggestAfterPatch(this.patch); + return this.tryCompleteLanding(this.patch); } return; } From 96a0a22e35fef85c3bb53729406bac3c97995241 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Fri, 14 Aug 2020 09:29:11 -0700 Subject: [PATCH 2/3] Potentially run make lint-js-fix --- lib/landing_session.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/landing_session.js b/lib/landing_session.js index e2059999..64cd9ddf 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -199,7 +199,13 @@ class LandingSession extends Session { const cleanLint = await this.validateLint(patch); if (!cleanLint) { - const correctedLint = await cli.prompt('Corrected lint errors?'); + const tryFixLint = await cli.prompt( + 'Try fixing JS lint with \'make lint-js-fix\'?'); + if (tryFixLint) { + await runAsync('make', ['lint-js-fix']); + } + + const correctedLint = await cli.prompt('Corrected all lint errors?'); if (correctedLint) { await runAsync('git', ['add', '.']); From 9c846de2ec0b1075e8929856cbd7377f04ad2624 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Sat, 15 Aug 2020 09:06:36 -0700 Subject: [PATCH 3/3] Clean up lint flow --- lib/landing_session.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/landing_session.js b/lib/landing_session.js index 64cd9ddf..371e1db2 100644 --- a/lib/landing_session.js +++ b/lib/landing_session.js @@ -132,18 +132,12 @@ class LandingSession extends Session { } async validateLint() { - const { cli } = this; - // The linter is currently only run on non-Windows platforms. if (os.platform() === 'win32') { return true; } const linted = await runAsync('make', ['lint']); - if (!linted) { - cli.warn('There are lint errors in your patch. ' + - 'Please fix them before proceeding'); - } return linted; } @@ -197,12 +191,17 @@ class LandingSession extends Session { const patch = await this.downloadAndPatch(); - const cleanLint = await this.validateLint(patch); + const cleanLint = await this.validateLint(); if (!cleanLint) { const tryFixLint = await cli.prompt( - 'Try fixing JS lint with \'make lint-js-fix\'?'); + 'Lint failed - try fixing with \'make lint-js-fix\'?'); if (tryFixLint) { await runAsync('make', ['lint-js-fix']); + const fixed = await this.validateLint(); + if (!fixed) { + cli.warn('Patch still contains lint errors. ' + + 'Please fix manually before proceeding'); + } } const correctedLint = await cli.prompt('Corrected all lint errors?');