Skip to content

fix: lint during the landing process #435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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