Skip to content

Commit 65eba99

Browse files
committed
Adds better comments
1 parent 6c1bcd0 commit 65eba99

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

dist/main/index.js

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,32 @@ async function run() {
2020

2121
const coverageFile = await mergeCoverages(coverageFiles, tmpPath);
2222
const summary = await summarize(coverageFile);
23+
const totalCoverage = lcovTotal(coverageFile);
24+
const minimumCoverage = core.getInput('minimum-coverage');
2325
const gitHubToken = core.getInput('github-token').trim();
26+
const errorMessage = `The code coverage is too low. Expected at least ${minimumCoverage}.`;
27+
const isFailure = totalCoverage < minimumCoverage;
2428

2529
if (gitHubToken !== '' && github.context.eventName === 'pull_request') {
30+
const sha = github.context.payload.pull_request.head.sha;
31+
const shaShort = sha.substr(0, 7);
32+
let body = `### [LCOV](https://github.com/marketplace/actions/report-lcov) of commit [<code>${shaShort}</code>](${github.context.payload.pull_request.number}/commits/${sha}) during [${github.context.workflow} #${github.context.runNumber}](../actions/runs/${github.context.runId})\n<pre>${summary}</pre>`;
33+
34+
if (isFailure) {
35+
body += `\n:no_entry: ${errorMessage}`;
36+
}
37+
2638
await github.getOctokit(gitHubToken)
2739
.issues.createComment({
2840
owner: github.context.repo.owner,
2941
repo: github.context.repo.repo,
3042
issue_number: github.context.payload.pull_request.number,
31-
body: `<pre>${summary}</pre>`,
43+
body: body,
3244
});
3345
}
3446

35-
if (lcovTotal(coverageFile) < core.getInput('minimum-coverage')) {
36-
throw new Error('The code coverage is too low.');
47+
if (isFailure) {
48+
throw Error(errorMessage);
3749
}
3850
} catch (error) {
3951
core.setFailed(error.message);
@@ -104,7 +116,7 @@ async function summarize(coverageFile) {
104116
const lines = output
105117
.trim()
106118
.split(/\r?\n/)
107-
119+
108120
lines.shift(); // Removes "Reading tracefile..."
109121

110122
return lines.join('\n');

0 commit comments

Comments
 (0)