Skip to content

Commit 6b57d13

Browse files
added emojies
1 parent d6d387f commit 6b57d13

File tree

3 files changed

+82
-24
lines changed

3 files changed

+82
-24
lines changed

dist/main.js

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6024,6 +6024,28 @@ function uncovered(file, options) {
60246024
.join(", ");
60256025
}
60266026

6027+
/**
6028+
* Compares two arrays of objects and returns with unique lines update
6029+
* @param {number} pdiff value from diff percentage
6030+
* @returns {string} emoji string for negative/positive pdiff
6031+
*/
6032+
const renderEmoji = pdiff => {
6033+
if (pdiff < 0) return "🔴";
6034+
if (pdiff >= 0) return "🟢";
6035+
};
6036+
6037+
/**
6038+
* Compares two arrays of objects and returns with unique lines update
6039+
* @param {Array} otherArray
6040+
* @returns {Function} function with filtering non original lines
6041+
*/
6042+
const comparer = otherArray => current =>
6043+
otherArray.filter(
6044+
other =>
6045+
other.lines.found === current.lines.found &&
6046+
other.lines.hit === current.lines.hit,
6047+
).length === 0;
6048+
60276049
/**
60286050
* Github comment for monorepo
60296051
* @param {Array<{packageName, lcovPath}>} lcovArrayForMonorepo
@@ -6046,15 +6068,14 @@ function commentForMonorepo(
60466068
const plus = pdiff > 0 ? "+" : "";
60476069
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴";
60486070

6049-
const getColor = () => {
6050-
if (pdiff === 0) return 'inherit';
6051-
if (pdiff < 0) return 'red';
6052-
if (pdiff > 0) return 'green';
6053-
};
6054-
6055-
const diffTh = `<div style="color:${getColor};"}>${th(arrow, " ", plus, pdiff.toFixed(2), "%")}</div>`;
6071+
const pdiffHtml = baseLcov ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
6072+
let report = lcovObj.lcov;
60566073

6057-
const pdiffHtml = baseLcov ? diffTh : "";
6074+
if (baseLcov) {
6075+
const onlyInLcov = lcovObj.lcov.filter(comparer(baseLcov));
6076+
const onlyInBefore = baseLcov.filter(comparer(lcovObj.lcov));
6077+
report = onlyInBefore.concat(onlyInLcov);
6078+
}
60586079

60596080
return `${table(
60606081
tbody(
@@ -6066,7 +6087,7 @@ function commentForMonorepo(
60666087
),
60676088
)} \n\n ${details(
60686089
summary("Coverage Report"),
6069-
tabulate(lcovObj.lcov, options),
6090+
tabulate(report, options),
60706091
)} <br/>`;
60716092
});
60726093

@@ -6088,15 +6109,23 @@ function comment(lcov, before, options) {
60886109
const plus = pdiff > 0 ? "+" : "";
60896110
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴";
60906111

6091-
const pdiffHtml = before ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : "";
6112+
const pdiffHtml = before ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
6113+
6114+
let report = lcov;
6115+
6116+
if (before) {
6117+
const onlyInLcov = lcov.filter(comparer(before));
6118+
const onlyInBefore = before.filter(comparer(lcov));
6119+
report = onlyInBefore.concat(onlyInLcov);
6120+
}
60926121

60936122
return fragment(
60946123
`Coverage after merging ${b(options.head)} into ${b(
60956124
options.base,
60966125
)} <p></p>`,
60976126
table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))),
60986127
"\n\n",
6099-
details(summary("Coverage Report"), tabulate(lcov, options)),
6128+
details(summary("Coverage Report"), tabulate(report, options)),
61006129
);
61016130
}
61026131

@@ -6314,7 +6343,7 @@ async function main() {
63146343
commit: context.payload.pull_request.head.sha,
63156344
prefix: `${process.env.GITHUB_WORKSPACE}/`,
63166345
head: context.payload.pull_request.head.ref,
6317-
base: context.payload.pull_request.base.ref,
6346+
base: context.payload.pull_request.base.ref
63186347
};
63196348

63206349
const lcov = !monorepoBasePath && (await parse$1(raw));

src/comment.js

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@ import { details, summary, b, fragment, table, tbody, tr, th } from "./html";
22
import { percentage } from "./lcov";
33
import { tabulate } from "./tabulate";
44

5+
/**
6+
* Compares two arrays of objects and returns with unique lines update
7+
* @param {number} pdiff value from diff percentage
8+
* @returns {string} emoji string for negative/positive pdiff
9+
*/
10+
const renderEmoji = pdiff => {
11+
if (pdiff < 0) return "🔴";
12+
if (pdiff >= 0) return "🟢";
13+
};
14+
15+
/**
16+
* Compares two arrays of objects and returns with unique lines update
17+
* @param {Array} otherArray
18+
* @returns {Function} function with filtering non original lines
19+
*/
20+
const comparer = otherArray => current =>
21+
otherArray.filter(
22+
other =>
23+
other.lines.found === current.lines.found &&
24+
other.lines.hit === current.lines.hit,
25+
).length === 0;
26+
527
/**
628
* Github comment for monorepo
729
* @param {Array<{packageName, lcovPath}>} lcovArrayForMonorepo
@@ -24,15 +46,14 @@ export function commentForMonorepo(
2446
const plus = pdiff > 0 ? "+" : "";
2547
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴";
2648

27-
const getColor = () => {
28-
if (pdiff === 0) return 'inherit';
29-
if (pdiff < 0) return 'red';
30-
if (pdiff > 0) return 'green';
31-
};
32-
33-
const diffTh = `<div style="color:${getColor};"}>${th(arrow, " ", plus, pdiff.toFixed(2), "%")}</div>`;
49+
const pdiffHtml = baseLcov ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
50+
let report = lcovObj.lcov;
3451

35-
const pdiffHtml = baseLcov ? diffTh : "";
52+
if (baseLcov) {
53+
const onlyInLcov = lcovObj.lcov.filter(comparer(baseLcov));
54+
const onlyInBefore = baseLcov.filter(comparer(lcovObj.lcov));
55+
report = onlyInBefore.concat(onlyInLcov);
56+
}
3657

3758
return `${table(
3859
tbody(
@@ -44,7 +65,7 @@ export function commentForMonorepo(
4465
),
4566
)} \n\n ${details(
4667
summary("Coverage Report"),
47-
tabulate(lcovObj.lcov, options),
68+
tabulate(report, options),
4869
)} <br/>`;
4970
});
5071

@@ -66,15 +87,23 @@ export function comment(lcov, before, options) {
6687
const plus = pdiff > 0 ? "+" : "";
6788
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴";
6889

69-
const pdiffHtml = before ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : "";
90+
const pdiffHtml = before ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
91+
92+
let report = lcov;
93+
94+
if (before) {
95+
const onlyInLcov = lcov.filter(comparer(before));
96+
const onlyInBefore = before.filter(comparer(lcov));
97+
report = onlyInBefore.concat(onlyInLcov);
98+
}
7099

71100
return fragment(
72101
`Coverage after merging ${b(options.head)} into ${b(
73102
options.base,
74103
)} <p></p>`,
75104
table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))),
76105
"\n\n",
77-
details(summary("Coverage Report"), tabulate(lcov, options)),
106+
details(summary("Coverage Report"), tabulate(report, options)),
78107
);
79108
}
80109

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async function main() {
108108
commit: context.payload.pull_request.head.sha,
109109
prefix: `${process.env.GITHUB_WORKSPACE}/`,
110110
head: context.payload.pull_request.head.ref,
111-
base: context.payload.pull_request.base.ref,
111+
base: context.payload.pull_request.base.ref
112112
};
113113

114114
const lcov = !monorepoBasePath && (await parse(raw));

0 commit comments

Comments
 (0)