Skip to content

Commit c2e78e2

Browse files
committed
fix: lint during the landing process
1 parent 08bc3fc commit c2e78e2

1 file changed

Lines changed: 49 additions & 8 deletions

File tree

lib/landing_session.js

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
const path = require('path');
4+
const os = require('os');
45
const {
56
getUnmarkedDeprecations,
67
updateDeprecations
@@ -120,8 +121,25 @@ class LandingSession extends Session {
120121
return command;
121122
}
122123

123-
async suggestAfterPatch(patch) {
124+
async validateLint() {
124125
const { cli } = this;
126+
127+
// The linter is currently only run on non-Windows platforms.
128+
if (os.platform() === 'win32') {
129+
return true;
130+
}
131+
132+
const linted = await runAsync('make', ['lint']);
133+
if (!linted) {
134+
cli.warn('There are lint errors in your patch. ' +
135+
'Please fix them before proceeding');
136+
return false;
137+
}
138+
}
139+
140+
async tryCompleteLanding(patch) {
141+
const { cli } = this;
142+
125143
const subjects = patch.match(/Subject: \[PATCH.*?\].*/g);
126144
if (!subjects) {
127145
cli.warn('Cannot get number of commits in the patch. ' +
@@ -144,6 +162,7 @@ class LandingSession extends Session {
144162
if (!canFinal) {
145163
return;
146164
}
165+
147166
return this.final();
148167
}
149168

@@ -157,16 +176,36 @@ class LandingSession extends Session {
157176

158177
async apply() {
159178
const { cli } = this;
179+
180+
// Bail if another landing session is currently in progress.
160181
if (!this.isApplying()) {
161-
cli.warn('This session can not proceed to apply patches, ' +
162-
'run `git node land --abort`');
182+
cli.warn('Landing session already in progress - ' +
183+
'to start a new one run `git node land --abort`');
163184
return;
164185
}
165186
await this.tryResetBranch();
166187

167188
const patch = await this.downloadAndPatch();
189+
190+
const cleanLint = await this.validateLint(patch);
191+
if (!cleanLint) {
192+
const correctedLint = await cli.prompt('Corrected lint errors?');
193+
if (correctedLint) {
194+
await runAsync('git', ['add', '.']);
195+
196+
// Final message will be edited later - don't try to change it here.
197+
await runAsync('git', ['commit', '--amend', '--no-edit']);
198+
} else {
199+
cli.info('Please fix lint errors and then run ' +
200+
'`git node land --amend` followed by ' +
201+
'`git node land --continue`.');
202+
process.exit(1);
203+
}
204+
}
205+
168206
this.startAmending();
169-
await this.suggestAfterPatch(patch);
207+
208+
await this.tryCompleteLanding(patch);
170209
}
171210

172211
async amend() {
@@ -229,7 +268,8 @@ class LandingSession extends Session {
229268
async final() {
230269
const { cli, owner, repo, upstream, branch, prid } = this;
231270

232-
if (!this.readyToFinal()) { // check git rebase/am has been done
271+
// Check that git rebase/am has been completed.
272+
if (!this.readyToFinal()) {
233273
cli.warn('Not yet ready to final');
234274
cli.log('A git rebase/am is in progress.' +
235275
' Please complete it before running git node land --final');
@@ -291,13 +331,14 @@ class LandingSession extends Session {
291331
return this.amend();
292332
}
293333
if (this.isApplying()) {
294-
// We are resolving conflict
334+
// We're still resolving conflicts.
295335
if (this.amInProgress()) {
296336
cli.log('Looks like you are resolving a `git am` conflict');
297337
cli.log('Please run `git status` for help');
298-
} else { // The conflict has been resolved
338+
} else {
339+
// Conflicts has been resolved - amend.
299340
this.startAmending();
300-
return this.suggestAfterPatch(this.patch);
341+
return this.tryCompleteLanding(this.patch);
301342
}
302343
return;
303344
}

0 commit comments

Comments
 (0)