Skip to content

Commit 526c059

Browse files
eslint + clean-up
eslint + clean-up
1 parent 1b4b067 commit 526c059

File tree

3 files changed

+70
-24
lines changed

3 files changed

+70
-24
lines changed

dist/main.js

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6024,11 +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+
*/
60276032
const renderEmoji = pdiff => {
6028-
if (pdiff < 0) return "🔴";
6029-
if (pdiff >= 0) return "🟢";
6033+
if (pdiff < 0) return "🔴";
6034+
if (pdiff >= 0) return "🟢";
60306035
};
60316036

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+
60326049
/**
60336050
* Github comment for monorepo
60346051
* @param {Array<{packageName, lcovPath}>} lcovArrayForMonorepo
@@ -6052,6 +6069,13 @@ function commentForMonorepo(
60526069
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴";
60536070

60546071
const pdiffHtml = baseLcov ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
6072+
let report = lcovObj.lcov;
6073+
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+
}
60556079

60566080
return `${table(
60576081
tbody(
@@ -6063,7 +6087,7 @@ function commentForMonorepo(
60636087
),
60646088
)} \n\n ${details(
60656089
summary("Coverage Report"),
6066-
tabulate(lcovObj.lcov, options),
6090+
tabulate(report, options),
60676091
)} <br/>`;
60686092
});
60696093

@@ -6078,7 +6102,7 @@ function commentForMonorepo(
60786102
* @param {raw lcov} lcov
60796103
* @param {*} options
60806104
*/
6081-
function comment(lcov, before, options) {
6105+
async function comment(lcov, before, options) {
60826106
const pbefore = before ? percentage(before) : 0;
60836107
const pafter = before ? percentage(lcov) : 0;
60846108
const pdiff = pafter - pbefore;
@@ -6087,14 +6111,13 @@ function comment(lcov, before, options) {
60876111

60886112
const pdiffHtml = before ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
60896113

6090-
let report = lcov;
6091-
if (before) {
6092-
const uniqueResultBase = before.filter(obj => !lcov.some(obj2 => obj.lines === obj2.lines));
6093-
const uniqueResultLcov = lcov.filter(obj => !before.some(obj2 => obj.lines === obj2.lines));
6114+
let report = lcov;
60946115

6095-
report = uniqueResultBase.concat(uniqueResultLcov);
6096-
console.log(report);
6097-
}
6116+
if (before) {
6117+
const onlyInLcov = lcov.filter(comparer(before));
6118+
const onlyInBefore = before.filter(comparer(lcov));
6119+
report = onlyInBefore.concat(onlyInLcov);
6120+
}
60986121

60996122
return fragment(
61006123
`Coverage after merging ${b(options.head)} into ${b(
@@ -6320,7 +6343,7 @@ async function main() {
63206343
commit: context.payload.pull_request.head.sha,
63216344
prefix: `${process.env.GITHUB_WORKSPACE}/`,
63226345
head: context.payload.pull_request.head.ref,
6323-
base: context.payload.pull_request.base.ref,
6346+
base: context.payload.pull_request.base.ref
63246347
};
63256348

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

src/comment.js

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +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+
*/
510
const renderEmoji = pdiff => {
6-
if (pdiff < 0) return "🔴";
7-
if (pdiff >= 0) return "🟢";
11+
if (pdiff < 0) return "🔴";
12+
if (pdiff >= 0) return "🟢";
813
};
914

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+
1027
/**
1128
* Github comment for monorepo
1229
* @param {Array<{packageName, lcovPath}>} lcovArrayForMonorepo
@@ -30,6 +47,13 @@ export function commentForMonorepo(
3047
const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴";
3148

3249
const pdiffHtml = baseLcov ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
50+
let report = lcovObj.lcov;
51+
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+
}
3357

3458
return `${table(
3559
tbody(
@@ -41,7 +65,7 @@ export function commentForMonorepo(
4165
),
4266
)} \n\n ${details(
4367
summary("Coverage Report"),
44-
tabulate(lcovObj.lcov, options),
68+
tabulate(report, options),
4569
)} <br/>`;
4670
});
4771

@@ -56,7 +80,7 @@ export function commentForMonorepo(
5680
* @param {raw lcov} lcov
5781
* @param {*} options
5882
*/
59-
export function comment(lcov, before, options) {
83+
export async function comment(lcov, before, options) {
6084
const pbefore = before ? percentage(before) : 0;
6185
const pafter = before ? percentage(lcov) : 0;
6286
const pdiff = pafter - pbefore;
@@ -65,14 +89,13 @@ export function comment(lcov, before, options) {
6589

6690
const pdiffHtml = before ? th(renderEmoji(pdiff), " ", arrow, " ", plus, pdiff.toFixed(2), "%") : "";
6791

68-
let report = lcov;
69-
if (before) {
70-
const uniqueResultBase = before.filter(obj => !lcov.some(obj2 => obj.lines === obj2.lines));
71-
const uniqueResultLcov = lcov.filter(obj => !before.some(obj2 => obj.lines === obj2.lines));
92+
let report = lcov;
7293

73-
report = uniqueResultBase.concat(uniqueResultLcov);
74-
console.log(report);
75-
}
94+
if (before) {
95+
const onlyInLcov = lcov.filter(comparer(before));
96+
const onlyInBefore = before.filter(comparer(lcov));
97+
report = onlyInBefore.concat(onlyInLcov);
98+
}
7699

77100
return fragment(
78101
`Coverage after merging ${b(options.head)} into ${b(

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)