Skip to content

Commit

Permalink
fix: lint during the landing process (#435)
Browse files Browse the repository at this point in the history
Runs make lint after the patch has been downloaded and applied, and optionally stage and amend updated files if lint fails.
  • Loading branch information
Alicia Lopez committed Aug 17, 2020
1 parent ba5f180 commit 9a31dbb
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions lib/landing_session.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const path = require('path');
const os = require('os');
const {
getUnmarkedDeprecations,
updateDeprecations
Expand Down Expand Up @@ -130,8 +131,19 @@ class LandingSession extends Session {
return command;
}

async suggestAfterPatch(patch) {
async validateLint() {
// The linter is currently only run on non-Windows platforms.
if (os.platform() === 'win32') {
return true;
}

const linted = await runAsync('make', ['lint']);
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. ' +
Expand All @@ -154,6 +166,7 @@ class LandingSession extends Session {
if (!canFinal) {
return;
}

return this.final();
}

Expand All @@ -167,16 +180,47 @@ 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();
if (!cleanLint) {
const tryFixLint = await cli.prompt(
'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?');
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() {
Expand Down Expand Up @@ -239,7 +283,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');
Expand Down Expand Up @@ -301,13 +346,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;
}
Expand Down

0 comments on commit 9a31dbb

Please sign in to comment.