Skip to content

Commit

Permalink
feat: limit comment size (#26)
Browse files Browse the repository at this point in the history
* feat: limit comment size

* feat: changelog
  • Loading branch information
lucassabreu authored Feb 17, 2023
1 parent 942f81f commit 5609ae0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- when no files/lines are left after the filters the comment will show "No files reported or matching filters"
on the table.
- when the size of the comment becomes too big for Github, the table will be cut short with the comment
"Table truncated to fit comment"

## [0.8.0] - 2022-11-02

Expand Down
34 changes: 28 additions & 6 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89519,6 +89519,23 @@ var compareFile = function (n, o, lang) {
? span(":new:", { title: "new file" })
: compare(n, o, lang, true));
};
var limitedFragment = function (limit, noSpaceLeft) {
var children = [];
for (var _i = 2; _i < arguments.length; _i++) {
children[_i - 2] = arguments[_i];
}
limit -= noSpaceLeft.length;
var html = "";
for (var _a = 0, children_1 = children; _a < children_1.length; _a++) {
var c = children_1[_a];
var s = c.toString();
if (s.length > limit)
return html + noSpaceLeft;
limit -= s.length;
html += s;
}
return html;
};
var line = function (name, m, lang, o, showDelta) {
if (o === void 0) { o = null; }
if (showDelta === void 0) { showDelta = false; }
Expand Down Expand Up @@ -89564,15 +89581,20 @@ var tableWrap = function (c, o, showDelta) {
if (o === void 0) { o = null; }
if (showDelta === void 0) { showDelta = false; }
return function (summaryText) {
return details(summary(summaryText), "<br />", table(thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))), tbody.apply(void 0, (c.folders.size === 0
? [tr(td("No files reported or matching filters", { colspan: 4 }))]
: Array.from(c.folders.entries()).map(function (_a) {
return details(summary(summaryText), "<br />", table(thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))), 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())
.map(function (_a) {
var k = _a[0], folder = _a[1];
return fragment.apply(void 0, __spreadArray([tr(td(b(folder.name), { colspan: 4 }))], folder.files.map(function (f) {
return __spreadArray([
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);
}), false));
})))));
}), true);
})
.reduce(function (accum, item) { return __spreadArray(__spreadArray([], accum, true), item, true); }, []), false)))));
};
};

Expand Down
2 changes: 1 addition & 1 deletion bin/index.js.map

Large diffs are not rendered by default.

57 changes: 41 additions & 16 deletions src/html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,27 @@ const compareFile = (n: Coverage, o: null | Coverage, lang: string) =>
? span(":new:", { title: "new file" })
: compare(n, o, lang, true));

interface Stringable {
toString: () => string;
}

const limitedFragment = (
limit: number,
noSpaceLeft: string,
...children: Stringable[]
) => {
limit -= noSpaceLeft.length;
let html = "";
for (let c of children) {
const s = c.toString();
if (s.length > limit) return html + noSpaceLeft;
limit -= s.length;
html += s;
}

return html;
};

const line = (
name: string,
m: Metrics,
Expand Down Expand Up @@ -134,22 +155,26 @@ const tableWrap =
table(
thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))),
tbody(
...(c.folders.size === 0
? [tr(td("No files reported or matching filters", { colspan: 4 }))]
: Array.from(c.folders.entries()).map(([k, folder]) =>
fragment(
tr(td(b(folder.name), { colspan: 4 })),
...folder.files.map((f: File) =>
line(
`&nbsp; &nbsp;${link(folder.name, f.name)}`,
f.metrics,
lang,
o?.get(k, f.name)?.metrics,
showDelta
)
)
)
))
c.folders.size === 0
? tr(td("No files reported or matching filters", { colspan: 4 }))
: limitedFragment(
65536 - 4000,
tr(td(b("Table truncated to fit comment"), { colspan: 4 })),
...Array.from(c.folders.entries())
.map(([k, folder]) => [
tr(td(b(folder.name), { colspan: 4 })),
...folder.files.map((f: File) =>
line(
`&nbsp; &nbsp;${link(folder.name, f.name)}`,
f.metrics,
lang,
o?.get(k, f.name)?.metrics,
showDelta
)
),
])
.reduce((accum, item) => [...accum, ...item], [])
)
)
)
);

0 comments on commit 5609ae0

Please sign in to comment.