Skip to content

Commit

Permalink
fix: issue 34 - branchs => branches (#36)
Browse files Browse the repository at this point in the history
* fix: branchs => branches

* feat: hide branches column
  • Loading branch information
lucassabreu authored May 24, 2023
1 parent b795fd1 commit e682a94
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 42 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,14 @@ jobs:
with-chart: true
show-percentage-change-on-table: true
signature: "clover file to comment - only one package"

- name: clover file to comment - hide branches column
uses: ./.
with:
dir-prefix: /var/www/html
file: clover.onepackage.xml
base-file: clover.onepackage.base.xml
with-chart: true
show-percentage-change-on-table: true
with-branches: false
signature: "clover file to comment - hide branches column"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]


### Added

- option `with-branches` to control if the column `Branches` show be rendered

### Fixed

- plural of `branch` is `branches` ([#34](https://github.com/lucassabreu/comment-coverage-clover/issues/34))

## [0.9.2] - 2023-03-21

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ inputs:
with-table:
description: Add a table with a list of files and its coverage
default: true
with-branches:
description: Adds the column "Branches" with the branching coverage
default: true
show-percentage-change-on-table:
description: Show in percentage how much the file coverage changed per file
default: false
Expand Down
42 changes: 26 additions & 16 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89435,7 +89435,7 @@ var fromString = function (str) {
return new Stats({
lines: new Coverage(m.statements, m.coveredstatements),
methods: new Coverage(m.methods, m.coveredmethods),
branchs: new Coverage(m.conditionals, m.coveredconditionals)
branches: new Coverage(m.conditionals, m.coveredconditionals)
}, allFiles
.map(function (f) {
f._attributes.name = f._attributes.path || f._attributes.name;
Expand All @@ -89450,7 +89450,7 @@ var fromString = function (str) {
metrics: {
lines: new Coverage(m.statements, m.coveredstatements),
methods: new Coverage(m.methods, m.coveredmethods),
branchs: new Coverage(m.conditionals, m.coveredconditionals)
branches: new Coverage(m.conditionals, m.coveredconditionals)
}
}));
}, new Map()));
Expand Down Expand Up @@ -89543,10 +89543,11 @@ var limitedFragment = function (limit, noSpaceLeft) {
}
return html;
};
var line = function (name, m, lang, o, showDelta) {
var line = function (name, m, lang, o, showDelta, showBranchesColumn) {
if (o === void 0) { o = null; }
if (showDelta === void 0) { showDelta = false; }
return tr.apply(void 0, __spreadArray([td(name)], ["lines", "methods", "branchs"].map(function (p) {
if (showBranchesColumn === void 0) { showBranchesColumn = true; }
return tr.apply(void 0, __spreadArray([td(name)], __spreadArray(["lines", "methods"], (showBranchesColumn ? ["branches"] : []), true).map(function (p) {
return td(c2s(m[p], lang) +
(!showDelta ? "" : compareFile(m[p], o && o[p], lang)), {
align: "right"
Expand All @@ -89573,22 +89574,26 @@ var total = function (name, c, oldC) {
var link = function (folder, file) {
return a("".concat(baseUrl, "/").concat(folder, "/").concat(file), file);
};
var html = function (withTable, c, o, deltaPerFile) {
var html = function (c, o, configs) {
if (o === void 0) { o = null; }
if (deltaPerFile === void 0) { deltaPerFile = false; }
return (withTable ? tableWrap(c, o, deltaPerFile) : span)("Summary - ".concat([
if (configs === void 0) { configs = { withTable: false, deltaPerFile: false, showBranchesColumn: true }; }
return (configs.withTable
? tableWrap(c, o, configs.deltaPerFile, configs.showBranchesColumn)
: span)("Summary - ".concat([
total("Lines", c.total.lines, o === null || o === void 0 ? void 0 : o.total.lines),
total("Methods", c.total.methods, o === null || o === void 0 ? void 0 : o.total.methods),
total("Branchs", c.total.branchs, o === null || o === void 0 ? void 0 : o.total.branchs),
configs.showBranchesColumn &&
total("Branches", c.total.branches, o === null || o === void 0 ? void 0 : o.total.branches),
]
.filter(function (v) { return v; })
.join(" | ")));
};
var tableWrap = function (c, o, showDelta) {
var tableWrap = function (c, o, showDelta, showBranchesColumn) {
if (o === void 0) { o = null; }
if (showDelta === void 0) { showDelta = false; }
if (showBranchesColumn === void 0) { showBranchesColumn = true; }
return function (summaryText) {
return details(summary(summaryText), "<br />", table(thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))), tbody(c.folders.size === 0
return details(summary(summaryText), "<br />", table(thead(tr(th("Files"), th("Lines"), th("Methods"), showBranchesColumn && th("Branches"))), tbody(c.folders.size === 0
? tr(td("No files reported or matching filters", { colspan: 4 }))
: limitedFragment.apply(void 0, __spreadArray([65536 - 4000,
tr(td(b("Table truncated to fit comment"), { colspan: 4 }))], Array.from(c.folders.entries())
Expand All @@ -89598,7 +89603,7 @@ var tableWrap = function (c, o, showDelta) {
tr(td(b(folder.name), { colspan: 4 }))
], folder.files.map(function (f) {
var _a;
return line("&nbsp; &nbsp;".concat(link(folder.name, f.name)), f.metrics, lang, (_a = o === null || o === void 0 ? void 0 : o.get(k, f.name)) === null || _a === void 0 ? void 0 : _a.metrics, showDelta);
return line("&nbsp; &nbsp;".concat(link(folder.name, f.name)), f.metrics, lang, (_a = o === null || o === void 0 ? void 0 : o.get(k, f.name)) === null || _a === void 0 ? void 0 : _a.metrics, showDelta, showBranchesColumn);
}), true);
})
.reduce(function (accum, item) { return __spreadArray(__spreadArray([], accum, true), item, true); }, []), false)))));
Expand All @@ -89611,8 +89616,9 @@ var file = coreExports.getInput("file") || process.env.FILE;
var baseFile = coreExports.getInput("base-file") || process.env.BASE_FILE;
var onlyWithCover = coreExports.getBooleanInput("only-with-cover");
var onlyWithCoverableLines = coreExports.getBooleanInput("only-with-coverable-lines");
var withChart = coreExports.getInput("with-chart") == "true";
var withTable = coreExports.getInput("with-table") == "true";
var withChart = coreExports.getBooleanInput("with-chart");
var withTable = coreExports.getBooleanInput("with-table");
var showBranchesColumn = coreExports.getBooleanInput("with-branches");
var tableWithOnlyBellow = Number(coreExports.getInput("table-below-coverage") || 100);
var tableWithOnlyAbove = Number(coreExports.getInput("table-above-coverage") || 0);
var tableWithChangeAbove = Number(coreExports.getInput("table-coverage-change") || 0);
Expand All @@ -89635,15 +89641,19 @@ var comment = function (cStats, oldStats, coverageType) { return __awaiter$1(voi
}));
});
return [2 /*return*/, ((withChart ? chart(cStats, oldStats) : "") +
html(withTable, filter(cStats, {
html(filter(cStats, {
cover: onlyWithCover,
coverableLines: onlyWithCoverableLines
}, {
type: coverageType,
min: tableWithOnlyAbove,
max: tableWithOnlyBellow,
delta: tableWithChangeAbove
}, oldStats), oldStats, showPercentageChangePerFile))];
}, oldStats), oldStats, {
withTable: withTable,
deltaPerFile: showPercentageChangePerFile,
showBranchesColumn: showBranchesColumn
}))];
});
}); };
var filter = function (s, onlyWith, onlyBetween, o) {
Expand Down Expand Up @@ -89729,7 +89739,7 @@ var run = function () { return __awaiter$1(void 0, void 0, void 0, function () {
return __generator(this, function (_k) {
switch (_k.label) {
case 0:
if (!["lines", "methods", "branchs"].includes(tableWithTypeLimit)) {
if (!["lines", "methods", "branches"].includes(tableWithTypeLimit)) {
coreExports.error("there is no coverage type ".concat(tableWithTypeLimit));
return [2 /*return*/];
}
Expand Down
2 changes: 1 addition & 1 deletion bin/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/clover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const fromString = (str: string): Stats => {
{
lines: new Coverage(m.statements, m.coveredstatements),
methods: new Coverage(m.methods, m.coveredmethods),
branchs: new Coverage(m.conditionals, m.coveredconditionals),
branches: new Coverage(m.conditionals, m.coveredconditionals),
},
allFiles
.map((f) => {
Expand All @@ -92,7 +92,7 @@ export const fromString = (str: string): Stats => {
metrics: {
lines: new Coverage(m.statements, m.coveredstatements),
methods: new Coverage(m.methods, m.coveredmethods),
branchs: new Coverage(m.conditionals, m.coveredconditionals),
branches: new Coverage(m.conditionals, m.coveredconditionals),
},
})
),
Expand Down
48 changes: 32 additions & 16 deletions src/html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ const line = (
m: Metrics,
lang: string,
o: Metrics = null,
showDelta = false
showDelta = false,
showBranchesColumn = true
) =>
tr(
td(name),
...["lines", "methods", "branchs"].map((p) =>
td(
c2s(m[p], lang) +
(!showDelta ? "" : compareFile(m[p], o && o[p], lang)),
{
align: "right",
}
)
...["lines", "methods", ...(showBranchesColumn ? ["branches"] : [])].map(
(p) =>
td(
c2s(m[p], lang) +
(!showDelta ? "" : compareFile(m[p], o && o[p], lang)),
{
align: "right",
}
)
)
);

Expand Down Expand Up @@ -129,31 +131,44 @@ const link = (folder: string, file: string) =>
a(`${baseUrl}/${folder}/${file}`, file);

export const html = (
withTable: boolean,
c: Stats,
o: Stats = null,
deltaPerFile = false
configs: {
withTable: boolean;
deltaPerFile?: boolean;
showBranchesColumn?: boolean;
} = { withTable: false, deltaPerFile: false, showBranchesColumn: true }
): string =>
(withTable ? tableWrap(c, o, deltaPerFile) : span)(
(configs.withTable
? tableWrap(c, o, configs.deltaPerFile, configs.showBranchesColumn)
: span)(
"Summary - ".concat(
[
total("Lines", c.total.lines, o?.total.lines),
total("Methods", c.total.methods, o?.total.methods),
total("Branchs", c.total.branchs, o?.total.branchs),
configs.showBranchesColumn &&
total("Branches", c.total.branches, o?.total.branches),
]
.filter((v) => v)
.join(" | ")
)
);

const tableWrap =
(c: Stats, o: Stats = null, showDelta = false) =>
(c: Stats, o: Stats = null, showDelta = false, showBranchesColumn = true) =>
(summaryText: string): string =>
details(
summary(summaryText),
"<br />",
table(
thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))),
thead(
tr(
th("Files"),
th("Lines"),
th("Methods"),
showBranchesColumn && th("Branches")
)
),
tbody(
c.folders.size === 0
? tr(td("No files reported or matching filters", { colspan: 4 }))
Expand All @@ -169,7 +184,8 @@ const tableWrap =
f.metrics,
lang,
o?.get(k, f.name)?.metrics,
showDelta
showDelta,
showBranchesColumn
)
),
])
Expand Down
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ const file = getInput("file") || process.env.FILE;
let baseFile = getInput("base-file") || process.env.BASE_FILE;
const onlyWithCover = getBooleanInput("only-with-cover");
const onlyWithCoverableLines = getBooleanInput("only-with-coverable-lines");
const withChart = getInput("with-chart") == "true";
const withTable = getInput("with-table") == "true";
const withChart = getBooleanInput("with-chart");
const withTable = getBooleanInput("with-table");
const showBranchesColumn = getBooleanInput("with-branches");
const tableWithOnlyBellow = Number(getInput("table-below-coverage") || 100);
const tableWithOnlyAbove = Number(getInput("table-above-coverage") || 0);
const tableWithChangeAbove = Number(getInput("table-coverage-change") || 0);
Expand Down Expand Up @@ -52,7 +53,6 @@ const comment = async (
return (
(withChart ? chart(cStats, oldStats) : "") +
html(
withTable,
filter(
cStats,
{
Expand All @@ -68,7 +68,11 @@ const comment = async (
oldStats
),
oldStats,
showPercentageChangePerFile
{
withTable,
deltaPerFile: showPercentageChangePerFile,
showBranchesColumn,
}
)
);
};
Expand Down Expand Up @@ -177,7 +181,7 @@ const notFoundMessage =
"was not found, please check if the path is valid, or if it exists.";

const run = async () => {
if (!["lines", "methods", "branchs"].includes(tableWithTypeLimit)) {
if (!["lines", "methods", "branches"].includes(tableWithTypeLimit)) {
error(`there is no coverage type ${tableWithTypeLimit}`);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class Coverage {
export interface Metrics {
lines: Coverage;
methods: Coverage;
branchs: Coverage;
branches: Coverage;
}

export interface File {
Expand Down

0 comments on commit e682a94

Please sign in to comment.