Skip to content

Commit

Permalink
Add file diff change status icon
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillick committed Jan 6, 2023
1 parent 96a14cd commit 27b9198
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
22 changes: 18 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27175,13 +27175,26 @@ function renderFileSummaryFactory(inputs) {
const hasDiffs = ((_a = inputs.baseCoveragePath) === null || _a === void 0 ? void 0 : _a.length) > 0;
return function renderFileSummaryTableRow(summary) {
const linePercent = Number(summary.lines.percent);
let status = ":red_circle:";
// Overall file coverage status
let coverageStatus = ":red_circle:";
if (linePercent > 80) {
status = ":green_circle:";
coverageStatus = ":green_circle:";
}
else if (linePercent > 40) {
status = ":yellow_circle:";
coverageStatus = ":yellow_circle:";
}
// Diff change status for the file
// If any of the diffs are below zero, the file get's a negative icon
const minDiff = Object.values(summary).reduce((val, item) => {
if (typeof item === "object") {
const diff = Number(item.diff);
if (diff < val) {
return diff;
}
}
return val;
}, 0);
const changeStatus = minDiff < 0 ? "<br/>🔻" : "";
const formatText = (text) => {
if (summary.name === "Total") {
return `**${text}**`;
Expand All @@ -27195,7 +27208,8 @@ function renderFileSummaryFactory(inputs) {
}
return formatText(itemOut);
};
return (`| ${status} ${formatText(summary.name)} ` +
return (`| ${coverageStatus}${changeStatus} ` +
`| ${formatText(summary.name)} ` +
`| ${itemOutput(summary.statements)} ` +
`| ${itemOutput(summary.branches)} ` +
`| ${itemOutput(summary.functions)} ` +
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions dist/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Summary
All files
</summary>

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= all.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>

</details>
Expand All @@ -41,8 +41,10 @@ All files

<% if (changed.length){ %>

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
Changed files

| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= changed.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>
<% } %>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "test-coverage-reporter",
"version": "1.0.7",
"version": "1.0.8",
"description": "Generate a test coverage report for a PR",
"main": "dist/index.js",
"scripts": {
Expand Down
23 changes: 19 additions & 4 deletions src/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,27 @@ function renderFileSummaryFactory(inputs: Inputs) {
return function renderFileSummaryTableRow(summary: TemplateDiffSummary) {
const linePercent = Number(summary.lines.percent);

let status = ":red_circle:";
// Overall file coverage status
let coverageStatus = ":red_circle:";
if (linePercent > 80) {
status = ":green_circle:";
coverageStatus = ":green_circle:";
} else if (linePercent > 40) {
status = ":yellow_circle:";
coverageStatus = ":yellow_circle:";
}

// Diff change status for the file
// If any of the diffs are below zero, the file get's a negative icon
const minDiff = Object.values(summary).reduce((val, item) => {
if (typeof item === "object") {
const diff = Number(item.diff);
if (diff < val) {
return diff;
}
}
return val;
}, 0);
const changeStatus = minDiff < 0 ? "<br/>🔻" : "";

const formatText = (text: string) => {
if (summary.name === "Total") {
return `**${text}**`;
Expand All @@ -262,7 +276,8 @@ function renderFileSummaryFactory(inputs: Inputs) {
};

return (
`| ${status} ${formatText(summary.name)} ` +
`| ${coverageStatus}${changeStatus} ` +
`| ${formatText(summary.name)} ` +
`| ${itemOutput(summary.statements)} ` +
`| ${itemOutput(summary.branches)} ` +
`| ${itemOutput(summary.functions)} ` +
Expand Down
10 changes: 6 additions & 4 deletions src/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Summary
All files
</summary>

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= all.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>

</details>
Expand All @@ -41,8 +41,10 @@ All files

<% if (changed.length){ %>

| Name | Stmts | Branch | Funcs | Lines |
| ---- | ----- | ------ | ----- | ----- |
Changed files

| Name | Stmts | Branch | Funcs | Lines | |
| ---- | ----- | ------ | ----- | ----- | ----- |
<%= changed.map((fileSummary) => renderFileSummaryTableRow(fileSummary)).join('\n') %>
<% } %>

Expand Down

0 comments on commit 27b9198

Please sign in to comment.