Skip to content

Commit

Permalink
chore: format comment message
Browse files Browse the repository at this point in the history
  • Loading branch information
rgwozdz committed Feb 16, 2024
1 parent 6415df7 commit 2577466
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions ci/format-branch-coverage-changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,32 @@ const { writeFileSync } = require('fs');
const json2md = require('json2md');
const coverageSummary = require('../coverage_changes/coverage-summary.json');

const rows = Object.entries(coverageSummary).map(([filePath, value]) => {
const file =
filePath === 'total'
? 'All Changed Files'
: filePath.split('koop')[1] || filePath;
return [
file,
getValue(value.statements),
getValue(value.branches),
getValue(value.functions),
getValue(value.lines),
];
const rows = Object.entries(coverageSummary)
.filter(([filePath]) => {
return filePath !== 'total';
})
.map(([filePath, value]) => {
const packagePath = filePath.split('packages')[1];
return [
`packages${packagePath}`,
getValue(value.statements),
getValue(value.branches),
getValue(value.functions),
getValue(value.lines),
];
});

const headers = ['', 'Statements', 'Branches', 'Functions', 'Lines'];

const markdown = json2md([{ h2: 'Coverage Report'}, { table: { headers, rows } }]);
writeFileSync('ci/branch-coverage-changes.md', markdown, 'utf8');
const aligned = markdown.replace('| --- | ---------- | -------- | --------- | ----- |', '| --- | ----------: | --------: | ---------: | -----: |');
writeFileSync('ci/branch-coverage-changes.md', aligned, 'utf8');

function getValue(input) {
const val = input.pct;
if (val > 95) {
return `${val} :white_check_mark:`;
}

if (val < 50) {
return `${val} :bangbang:`;
}

return `${val} :heavy_exclamation_mark:`;
return `${input.pct} <div style="width:0.8em; height:0.75em; display:inline-block; vertical-align:middle; margin-bottom:0.1em; background-color:${getGreenToRed(input.pct)}"></div>`;
}

function getGreenToRed(percent) {
const g = (255 * percent) / 100;
const r = 255 - (255 * percent) / 100;
return 'rgb(' + r + ',' + g + ',0)';
}

0 comments on commit 2577466

Please sign in to comment.