Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
slavcodev committed Feb 26, 2022
1 parent 6829b14 commit c9ee71b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
22 changes: 13 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14941,21 +14941,21 @@ function generateTableRow(title, {
}

function generateTable({
report,
report: { metrics, threshold: { metric } },
context,
}) {
const metric = report.metrics[report.threshold.metric];
const { rate, level } = metrics[metric];

return `${generateCommentHeader({ context })}
## ${context}${generateEmoji(metric)}
## ${context}${generateEmoji({ rate })}

| Totals | ![Coverage](${generateBadgeUrl(metric)}) |
| Totals | ![Coverage](${generateBadgeUrl({ rate, level })}) |
| :-- | :-- |
${[
generateTableRow('Statements', report.metrics.statements),
generateTableRow('Methods', report.metrics.methods),
generateTableRow('Lines', report.metrics.lines),
generateTableRow('Branches', report.metrics.branches),
generateTableRow('Statements', metrics.statements),
generateTableRow('Methods', metrics.methods),
generateTableRow('Lines', metrics.lines),
generateTableRow('Branches', metrics.branches),
].join('')}`;
}

Expand Down Expand Up @@ -14994,7 +14994,9 @@ function toBool(value, def) {
}

function toBips(value, def) {
return Math.round(Number(value) * 100) || def;
return value !== undefined
? Math.round(Number(value) * 100)
: def;
}

function getWorkingDirectory() {
Expand Down Expand Up @@ -15637,6 +15639,8 @@ async function run() {

const report = generateReport(threshold, await parseFile(workingDir, coveragePath, coverageFormat));

core.debug(`Report generated: ${JSON.stringify(report)}`);

if (pr) {
const client = github.getOctokit(githubToken).rest;

Expand Down
16 changes: 8 additions & 8 deletions src/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ function generateTableRow(title, {
}

function generateTable({
report,
report: { metrics, threshold: { metric } },
context,
}) {
const metric = report.metrics[report.threshold.metric];
const { rate, level } = metrics[metric];

return `${generateCommentHeader({ context })}
## ${context}${generateEmoji(metric)}
## ${context}${generateEmoji({ rate })}
| Totals | ![Coverage](${generateBadgeUrl(metric)}) |
| Totals | ![Coverage](${generateBadgeUrl({ rate, level })}) |
| :-- | :-- |
${[
generateTableRow('Statements', report.metrics.statements),
generateTableRow('Methods', report.metrics.methods),
generateTableRow('Lines', report.metrics.lines),
generateTableRow('Branches', report.metrics.branches),
generateTableRow('Statements', metrics.statements),
generateTableRow('Methods', metrics.methods),
generateTableRow('Lines', metrics.lines),
generateTableRow('Branches', metrics.branches),
].join('')}`;
}

Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ async function run() {

const report = generateReport(threshold, await parseFile(workingDir, coveragePath, coverageFormat));

core.debug(`Report generated: ${JSON.stringify(report)}`);

if (pr) {
const client = github.getOctokit(githubToken).rest;

Expand Down
3 changes: 2 additions & 1 deletion tests/report.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ describe(`${calculateLevel.name}`, () => {
{ rate: 90, threshold: defaultThreshold, level: 'green' },
{ rate: 91, threshold: defaultThreshold, level: 'green' },
{ rate: 100, threshold: defaultThreshold, level: 'green' },
])('calculates level $rate with $threshold', async ({ rate, threshold, level }) => {
{ rate: 95, threshold: { ...defaultThreshold, alert: 0 }, level: 'green' },
])('calculates level $rate with $threshold is $level', async ({ rate, threshold, level }) => {
expect.hasAssertions();
expect(calculateLevel(rate, threshold)).toBe(level);
});
Expand Down

0 comments on commit c9ee71b

Please sign in to comment.