Skip to content

Commit 5609ae0

Browse files
authored
feat: limit comment size (#26)
* feat: limit comment size * feat: changelog
1 parent 942f81f commit 5609ae0

File tree

4 files changed

+72
-23
lines changed

4 files changed

+72
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

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

1416
## [0.8.0] - 2022-11-02
1517

bin/index.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89519,6 +89519,23 @@ var compareFile = function (n, o, lang) {
8951989519
? span(":new:", { title: "new file" })
8952089520
: compare(n, o, lang, true));
8952189521
};
89522+
var limitedFragment = function (limit, noSpaceLeft) {
89523+
var children = [];
89524+
for (var _i = 2; _i < arguments.length; _i++) {
89525+
children[_i - 2] = arguments[_i];
89526+
}
89527+
limit -= noSpaceLeft.length;
89528+
var html = "";
89529+
for (var _a = 0, children_1 = children; _a < children_1.length; _a++) {
89530+
var c = children_1[_a];
89531+
var s = c.toString();
89532+
if (s.length > limit)
89533+
return html + noSpaceLeft;
89534+
limit -= s.length;
89535+
html += s;
89536+
}
89537+
return html;
89538+
};
8952289539
var line = function (name, m, lang, o, showDelta) {
8952389540
if (o === void 0) { o = null; }
8952489541
if (showDelta === void 0) { showDelta = false; }
@@ -89564,15 +89581,20 @@ var tableWrap = function (c, o, showDelta) {
8956489581
if (o === void 0) { o = null; }
8956589582
if (showDelta === void 0) { showDelta = false; }
8956689583
return function (summaryText) {
89567-
return details(summary(summaryText), "<br />", table(thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))), tbody.apply(void 0, (c.folders.size === 0
89568-
? [tr(td("No files reported or matching filters", { colspan: 4 }))]
89569-
: Array.from(c.folders.entries()).map(function (_a) {
89584+
return details(summary(summaryText), "<br />", table(thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))), tbody(c.folders.size === 0
89585+
? tr(td("No files reported or matching filters", { colspan: 4 }))
89586+
: limitedFragment.apply(void 0, __spreadArray([65536 - 4000,
89587+
tr(td(b("Table truncated to fit comment"), { colspan: 4 }))], Array.from(c.folders.entries())
89588+
.map(function (_a) {
8957089589
var k = _a[0], folder = _a[1];
89571-
return fragment.apply(void 0, __spreadArray([tr(td(b(folder.name), { colspan: 4 }))], folder.files.map(function (f) {
89590+
return __spreadArray([
89591+
tr(td(b(folder.name), { colspan: 4 }))
89592+
], folder.files.map(function (f) {
8957289593
var _a;
8957389594
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);
89574-
}), false));
89575-
})))));
89595+
}), true);
89596+
})
89597+
.reduce(function (accum, item) { return __spreadArray(__spreadArray([], accum, true), item, true); }, []), false)))));
8957689598
};
8957789599
};
8957889600

bin/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/html/index.ts

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,27 @@ const compareFile = (n: Coverage, o: null | Coverage, lang: string) =>
5050
? span(":new:", { title: "new file" })
5151
: compare(n, o, lang, true));
5252

53+
interface Stringable {
54+
toString: () => string;
55+
}
56+
57+
const limitedFragment = (
58+
limit: number,
59+
noSpaceLeft: string,
60+
...children: Stringable[]
61+
) => {
62+
limit -= noSpaceLeft.length;
63+
let html = "";
64+
for (let c of children) {
65+
const s = c.toString();
66+
if (s.length > limit) return html + noSpaceLeft;
67+
limit -= s.length;
68+
html += s;
69+
}
70+
71+
return html;
72+
};
73+
5374
const line = (
5475
name: string,
5576
m: Metrics,
@@ -134,22 +155,26 @@ const tableWrap =
134155
table(
135156
thead(tr(th("Files"), th("Lines"), th("Methods"), th("Branchs"))),
136157
tbody(
137-
...(c.folders.size === 0
138-
? [tr(td("No files reported or matching filters", { colspan: 4 }))]
139-
: Array.from(c.folders.entries()).map(([k, folder]) =>
140-
fragment(
141-
tr(td(b(folder.name), { colspan: 4 })),
142-
...folder.files.map((f: File) =>
143-
line(
144-
`&nbsp; &nbsp;${link(folder.name, f.name)}`,
145-
f.metrics,
146-
lang,
147-
o?.get(k, f.name)?.metrics,
148-
showDelta
149-
)
150-
)
151-
)
152-
))
158+
c.folders.size === 0
159+
? tr(td("No files reported or matching filters", { colspan: 4 }))
160+
: limitedFragment(
161+
65536 - 4000,
162+
tr(td(b("Table truncated to fit comment"), { colspan: 4 })),
163+
...Array.from(c.folders.entries())
164+
.map(([k, folder]) => [
165+
tr(td(b(folder.name), { colspan: 4 })),
166+
...folder.files.map((f: File) =>
167+
line(
168+
`&nbsp; &nbsp;${link(folder.name, f.name)}`,
169+
f.metrics,
170+
lang,
171+
o?.get(k, f.name)?.metrics,
172+
showDelta
173+
)
174+
),
175+
])
176+
.reduce((accum, item) => [...accum, ...item], [])
177+
)
153178
)
154179
)
155180
);

0 commit comments

Comments
 (0)