Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const main = async () => {
const repoName = context.repo.repo;
const repoOwner = context.repo.owner;
const githubToken = core.getInput("github-token");
const testCommand = core.getInput("test-command") || "npx jest";
const githubClient = new GitHub(githubToken);
const commitPRs = await githubClient.repos.listPullRequestsAssociatedWithCommit(
{
repo: repoName,
owner: repoOwner,
commit_sha: context.sha
}
);
const prNumber = commitPRs.data[0].number;
const codeCoverage = execSync(testCommand).toString();
let coveragePercentage = execSync(
"npx coverage-percentage ./coverage/lcov.info --lcov"
).toString();
coveragePercentage = parseFloat(coveragePercentage).toFixed(2);
const commentBody = `<p>Total Coverage: <code>${coveragePercentage}</code></p>
<details><summary>Coverage report</summary>
<p>
</p><pre>${codeCoverage}</pre>
<p></p>
</details>`;