Skip to content

Commit 5938f12

Browse files
authored
Merge pull request #335 from happo/async-github-user-credentials
Allow HAPPO_GITHUB_USER_CREDENTIALS to work with async comparisons
2 parents 5c257d5 + de67243 commit 5938f12

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/executeCli.js

+23-12
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,26 @@ commander
5353
.description('execute a full happo run')
5454
.action(async (sha) => {
5555
let usedSha = sha || generateDevSha();
56+
5657
if (!sha) {
5758
new Logger().info(
5859
`No [sha] provided. A temporary one will be used in place: "${usedSha}".`,
5960
);
6061
}
62+
6163
if (commander.only) {
6264
usedSha = `${usedSha}-${commander.only}`;
6365
}
66+
6467
const isAsync = commander.async || HAPPO_IS_ASYNC;
6568
await runCommand(usedSha, await loadUserConfig(commander.config), {
6669
only: commander.only,
6770
link: commander.link,
6871
isAsync,
6972
message: commander.message,
7073
});
71-
process.exit(0);
74+
75+
process.exitCode = 0;
7276
});
7377

7478
commander
@@ -95,9 +99,9 @@ commander
9599
.description('check if there is a report for a specific sha')
96100
.action(async (sha) => {
97101
if (await hasReportCommand(sha, await loadUserConfig(commander.config))) {
98-
process.exit(0);
102+
process.exitCode = 0;
99103
} else {
100-
process.exit(1);
104+
process.exitCode = 1;
101105
}
102106
});
103107

@@ -110,7 +114,8 @@ commander
110114
sha,
111115
...(await loadUserConfig(commander.config)),
112116
});
113-
process.exit(0);
117+
118+
process.exitCode = 0;
114119
});
115120

116121
commander
@@ -130,10 +135,6 @@ commander
130135
isAsync,
131136
fallbackShas,
132137
});
133-
if (isAsync) {
134-
new Logger().info(`Async comparison created with ID=${result.id}`);
135-
process.exit(0);
136-
}
137138
if (commander.link && process.env.HAPPO_GITHUB_USER_CREDENTIALS) {
138139
await postGithubComment({
139140
link: commander.link,
@@ -142,11 +143,19 @@ commander
142143
githubApiUrl: config.githubApiUrl,
143144
});
144145
}
146+
147+
if (isAsync) {
148+
new Logger().info(`Async comparison created with ID=${result.id}`);
149+
process.exitCode = 0;
150+
return;
151+
}
152+
145153
new Logger().info(result.summary);
154+
146155
if (result.equal) {
147-
process.exit(0);
156+
process.exitCode = 0;
148157
} else {
149-
process.exit(113);
158+
process.exitCode = 113;
150159
}
151160
});
152161

@@ -163,20 +172,22 @@ commander
163172
},
164173
await loadUserConfig(commander.config),
165174
);
175+
166176
new Logger().info(result.id);
167177
});
168178

169179
commander.on('command:*', (cmd) => {
170180
console.log(`Invalid command: "${cmd}"\n`);
171181
commander.outputHelp();
172-
process.exit(1);
182+
process.exitCode = 1;
173183
});
174184

175185
export default function executeCli(argv) {
176186
if (!argv.slice(2).length) {
177187
commander.outputHelp();
178-
process.exit(1);
188+
process.exitCode = 1;
179189
return;
180190
}
191+
181192
return commander.parse(argv);
182193
}

0 commit comments

Comments
 (0)