Skip to content
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

Allow HAPPO_GITHUB_USER_CREDENTIALS to work with async comparisons #335

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
35 changes: 23 additions & 12 deletions src/executeCli.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,26 @@ commander
.description('execute a full happo run')
.action(async (sha) => {
let usedSha = sha || generateDevSha();

if (!sha) {
new Logger().info(
`No [sha] provided. A temporary one will be used in place: "${usedSha}".`,
);
}

if (commander.only) {
usedSha = `${usedSha}-${commander.only}`;
}

const isAsync = commander.async || HAPPO_IS_ASYNC;
await runCommand(usedSha, await loadUserConfig(commander.config), {
only: commander.only,
link: commander.link,
isAsync,
message: commander.message,
});
process.exit(0);

process.exitCode = 0;
});

commander
Expand All @@ -95,9 +99,9 @@ commander
.description('check if there is a report for a specific sha')
.action(async (sha) => {
if (await hasReportCommand(sha, await loadUserConfig(commander.config))) {
process.exit(0);
process.exitCode = 0;
} else {
process.exit(1);
process.exitCode = 1;
}
});

Expand All @@ -110,7 +114,8 @@ commander
sha,
...(await loadUserConfig(commander.config)),
});
process.exit(0);

process.exitCode = 0;
});

commander
Expand All @@ -130,10 +135,6 @@ commander
isAsync,
fallbackShas,
});
if (isAsync) {
new Logger().info(`Async comparison created with ID=${result.id}`);
process.exit(0);
}
if (commander.link && process.env.HAPPO_GITHUB_USER_CREDENTIALS) {
await postGithubComment({
link: commander.link,
Expand All @@ -142,11 +143,19 @@ commander
githubApiUrl: config.githubApiUrl,
});
}

if (isAsync) {
new Logger().info(`Async comparison created with ID=${result.id}`);
process.exitCode = 0;
return;
}

new Logger().info(result.summary);

if (result.equal) {
process.exit(0);
process.exitCode = 0;
} else {
process.exit(113);
process.exitCode = 113;
}
});

Expand All @@ -163,20 +172,22 @@ commander
},
await loadUserConfig(commander.config),
);

new Logger().info(result.id);
});

commander.on('command:*', (cmd) => {
console.log(`Invalid command: "${cmd}"\n`);
commander.outputHelp();
process.exit(1);
process.exitCode = 1;
});

export default function executeCli(argv) {
if (!argv.slice(2).length) {
commander.outputHelp();
process.exit(1);
process.exitCode = 1;
return;
}

return commander.parse(argv);
}