Skip to content

Commit 4402e36

Browse files
committed
fix: lint during the landing process
1 parent d3816ad commit 4402e36

File tree

1 file changed

+43
-8
lines changed

1 file changed

+43
-8
lines changed

lib/landing_session.js

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,20 @@ class LandingSession extends Session {
103103
return command;
104104
}
105105

106-
async suggestAfterPatch(patch) {
106+
async validateLint() {
107107
const { cli } = this;
108+
109+
const linted = await runAsync('make', ['lint']);
110+
if (!linted) {
111+
cli.warn('There are lint errors in your patch. ' +
112+
'Please fix them before proceeding');
113+
return false;
114+
}
115+
}
116+
117+
async tryCompleteLanding(patch) {
118+
const { cli } = this;
119+
108120
const subjects = patch.match(/Subject: \[PATCH.*?\].*/g);
109121
if (!subjects) {
110122
cli.warn('Cannot get number of commits in the patch. ' +
@@ -127,6 +139,7 @@ class LandingSession extends Session {
127139
if (!canFinal) {
128140
return;
129141
}
142+
130143
return this.final();
131144
}
132145

@@ -140,16 +153,36 @@ class LandingSession extends Session {
140153

141154
async apply() {
142155
const { cli } = this;
156+
157+
// Bail if another landing session is currently in progress.
143158
if (!this.isApplying()) {
144-
cli.warn('This session can not proceed to apply patches, ' +
145-
'run `git node land --abort`');
159+
cli.warn('Landing session already in progress - ' +
160+
'to start a new one run `git node land --abort`');
146161
return;
147162
}
148163
await this.tryResetBranch();
149164

150165
const patch = await this.downloadAndPatch();
166+
167+
const cleanLint = await this.validateLint(patch);
168+
if (!cleanLint) {
169+
const correctedLint = await cli.prompt('Corrected lint errors?');
170+
if (correctedLint) {
171+
await runAsync('git', ['add', '.']);
172+
173+
// Final message will be edited later - don't try to change it here.
174+
await runAsync('git', ['commit', '--amend', '--no-edit']);
175+
} else {
176+
cli.info('Please fix lint errors and then run ' +
177+
'`git node land --amend` followed by ' +
178+
'`git node land --continue`.');
179+
process.exit(1);
180+
}
181+
}
182+
151183
this.startAmending();
152-
await this.suggestAfterPatch(patch);
184+
185+
await this.tryCompleteLanding(patch);
153186
}
154187

155188
async amend() {
@@ -212,7 +245,8 @@ class LandingSession extends Session {
212245
async final() {
213246
const { cli, owner, repo, upstream, branch, prid } = this;
214247

215-
if (!this.readyToFinal()) { // check git rebase/am has been done
248+
// Check that git rebase/am has been completed.
249+
if (!this.readyToFinal()) {
216250
cli.warn('Not yet ready to final');
217251
cli.log('A git rebase/am is in progress.' +
218252
' Please complete it before running git node land --final');
@@ -274,13 +308,14 @@ class LandingSession extends Session {
274308
return this.amend();
275309
}
276310
if (this.isApplying()) {
277-
// We are resolving conflict
311+
// We're still resolving conflicts.
278312
if (this.amInProgress()) {
279313
cli.log('Looks like you are resolving a `git am` conflict');
280314
cli.log('Please run `git status` for help');
281-
} else { // The conflict has been resolved
315+
} else {
316+
// Conflicts has been resolved - amend.
282317
this.startAmending();
283-
return this.suggestAfterPatch(this.patch);
318+
return this.tryCompleteLanding(this.patch);
284319
}
285320
return;
286321
}

0 commit comments

Comments
 (0)