|
| 1 | +const { writeFileSync } = require('fs'); |
| 2 | +const json2md = require('json2md'); |
| 3 | +const coverageSummary = require('../coverage_changes/coverage-summary.json'); |
| 4 | + |
| 5 | +const rows = Object.entries(coverageSummary) |
| 6 | + .filter(([filePath]) => { |
| 7 | + return filePath !== 'total'; |
| 8 | + }) |
| 9 | + .map(([filePath, value]) => { |
| 10 | + const packagePath = filePath.split('packages')[1]; |
| 11 | + return [ |
| 12 | + `packages${packagePath}`, |
| 13 | + getValue(value.statements), |
| 14 | + getValue(value.branches), |
| 15 | + getValue(value.functions), |
| 16 | + getValue(value.lines), |
| 17 | + ]; |
| 18 | + }); |
| 19 | + |
| 20 | +const headers = ['File Path', 'Statements', 'Branches', 'Functions', 'Lines']; |
| 21 | +const markdown = json2md([{ h2: 'Coverage Report'}, { table: { headers, rows } }]); |
| 22 | +const aligned = markdown.replace('| --------- | ---------- | -------- | --------- | ----- |', '| :--------- | ----------: | --------: | ---------: | -----: |'); |
| 23 | +writeFileSync('ci/branch-coverage-changes.md', aligned, 'utf8'); |
| 24 | + |
| 25 | +function getValue(input) { |
| 26 | + if (input.pct === 100) { |
| 27 | + return `${input.pct} `; |
| 28 | + } |
| 29 | + |
| 30 | + if (input.pct > 90) { |
| 31 | + return `${input.pct} `; |
| 32 | + } |
| 33 | + |
| 34 | + if (input.pct > 80) { |
| 35 | + return `${input.pct} `; |
| 36 | + } |
| 37 | + |
| 38 | + if (input.pct > 70) { |
| 39 | + return `${input.pct} `; |
| 40 | + } |
| 41 | + |
| 42 | + return `${input.pct} `; |
| 43 | +} |
| 44 | + |
0 commit comments