@@ -13893,43 +13893,10 @@ module.exports = { addComment, deleteExistingComments };
1389313893
1389413894/***/ }),
1389513895
13896- /***/ 109 :
13896+ /***/ 1752 :
1389713897/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
1389813898
13899- const simpleGit = __nccwpck_require__(4959);
13900-
13901- async function gitClone(url, wikiPath) {
13902- return await simpleGit().clone(url, wikiPath);
13903- }
13904-
13905- async function gitUpdate(wikiPath) {
13906- return await simpleGit(wikiPath)
13907- .addConfig("user.name", "Coverage Diff Action")
13908- .addConfig("user.email", "coverage-diff-action")
13909- .add("*")
13910- .commit("Update coverage badge")
13911- .push();
13912- }
13913-
13914- module.exports = { gitClone, gitUpdate };
13915-
13916-
13917- /***/ }),
13918-
13919- /***/ 8978:
13920- /***/ ((module) => {
13921-
13922- function average(arr, fixed = 2) {
13923- return Math.round(arr.reduce((a, b) => a + b, 0) / arr.length).toFixed(fixed);
13924- }
13925-
13926- module.exports = { average };
13927-
13928-
13929- /***/ }),
13930-
13931- /***/ 1397:
13932- /***/ ((module) => {
13899+ const coverageDiff = __nccwpck_require__(6387);
1393313900
1393413901const ICONS = {
1393513902 OK: "✅",
@@ -13946,36 +13913,34 @@ function _renderPct(pct, addSign = true) {
1394613913 return `${pct.toFixed(2)}%`;
1394713914}
1394813915
13949- function renderDiff(base, head, diff, options = {}) {
13916+ function computeDiff(base, head, options = {}) {
13917+ const diff = coverageDiff.diff(base, head);
13918+
1395013919 let totalTitle = "Total coverage";
13951- if (diff.regression) {
13952- totalTitle = `${
13953- options.allowedToFail ? ICONS.WARN : ICONS.KO
13954- } Total coverage is lower than the default branch`;
13955- }
13920+ let summaryTitle = "click to open the diff coverage report";
1395613921
1395713922 let countRegression = 0;
13958- let summaryTitle = "click to open the diff coverage report";
1395913923 let table = [];
13960-
1396113924 Object.keys(diff.diff).forEach((file) => {
1396213925 if (file === "total") {
1396313926 return;
1396413927 }
1396513928
13966- let element = diff.diff[file];
13929+ const element = diff.diff[file];
1396713930
1396813931 if (CRITERIAS.every((criteria) => element[criteria].pct === 0)) {
1396913932 return;
1397013933 }
1397113934
13972- let regression = CRITERIAS.some((criteria) => element[criteria].pct < 0);
13973- if (regression) {
13935+ const fileRegression = CRITERIAS.some(
13936+ (criteria) => element[criteria].pct < 0
13937+ );
13938+ if (fileRegression) {
1397413939 countRegression++;
1397513940 }
1397613941
1397713942 table.push({
13978- icon: regression ? ICONS.KO : ICONS.OK,
13943+ icon: fileRegression ? ICONS.KO : ICONS.OK,
1397913944 filename: file,
1398013945 lines: {
1398113946 pct: _renderPct(head[file].lines.pct, false),
@@ -14001,21 +13966,34 @@ function renderDiff(base, head, diff, options = {}) {
1400113966 }
1400213967
1400313968 let totals = {};
13969+ let globalRegression = false;
1400413970 CRITERIAS.forEach((criteria) => {
13971+ let diffPct = head.total[criteria].pct - base.total[criteria].pct;
13972+ if (diffPct < 0) {
13973+ globalRegression = true;
13974+ }
1400513975 totals[criteria] = `${_renderPct(
1400613976 head.total[criteria].pct,
1400713977 false
14008- )} (${_renderPct(head.total[criteria].pct - base.total[criteria].pct )})`;
13978+ )} (${_renderPct(diffPct )})`;
1400913979 });
1401013980
14011- return `
13981+ if (globalRegression) {
13982+ totalTitle = `${
13983+ options.allowedToFail ? ICONS.WARN : ICONS.KO
13984+ } Total coverage is lower than the default branch`;
13985+ }
13986+
13987+ return {
13988+ regression: globalRegression,
13989+ markdown: `
1401213990### ${totalTitle}
1401313991
1401413992| Lines | Branches | Functions | Statements |
1401513993| --------------- | ------------------ | ------------------- | -------------------- |
1401613994| ${totals.lines} | ${totals.branches} | ${totals.functions} | ${
14017- totals.statements
14018- } |
13995+ totals.statements
13996+ } |
1401913997${
1402013998 table.length > 0
1402113999 ? `
@@ -14040,10 +14018,46 @@ ${
1404014018</details>`
1404114019 : ""
1404214020}
14043- `;
14021+ `,
14022+ };
1404414023}
1404514024
14046- module.exports = { renderDiff };
14025+ module.exports = { computeDiff };
14026+
14027+
14028+ /***/ }),
14029+
14030+ /***/ 109:
14031+ /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
14032+
14033+ const simpleGit = __nccwpck_require__(4959);
14034+
14035+ async function gitClone(url, wikiPath) {
14036+ return await simpleGit().clone(url, wikiPath);
14037+ }
14038+
14039+ async function gitUpdate(wikiPath) {
14040+ return await simpleGit(wikiPath)
14041+ .addConfig("user.name", "Coverage Diff Action")
14042+ .addConfig("user.email", "coverage-diff-action")
14043+ .add("*")
14044+ .commit("Update coverage badge")
14045+ .push();
14046+ }
14047+
14048+ module.exports = { gitClone, gitUpdate };
14049+
14050+
14051+ /***/ }),
14052+
14053+ /***/ 8978:
14054+ /***/ ((module) => {
14055+
14056+ function average(arr, fixed = 2) {
14057+ return Math.round(arr.reduce((a, b) => a + b, 0) / arr.length).toFixed(fixed);
14058+ }
14059+
14060+ module.exports = { average };
1404714061
1404814062
1404914063/***/ }),
@@ -14254,13 +14268,12 @@ const { existsSync } = __nccwpck_require__(7147);
1425414268const path = __nccwpck_require__(1017);
1425514269const core = __nccwpck_require__(2186);
1425614270const github = __nccwpck_require__(5438);
14257- const coverageDiff = __nccwpck_require__(6387);
1425814271
1425914272const { gitClone, gitUpdate } = __nccwpck_require__(109);
1426014273const { isBranch, isMainBranch } = __nccwpck_require__(6381);
1426114274const { getShieldURL, getJSONBadge } = __nccwpck_require__(3673);
1426214275const { average } = __nccwpck_require__(8978);
14263- const { renderDiff } = __nccwpck_require__(1397 );
14276+ const { computeDiff } = __nccwpck_require__(1752 );
1426414277const { addComment, deleteExistingComments } = __nccwpck_require__(427);
1426514278
1426614279const { context } = github;
@@ -14333,28 +14346,19 @@ async function run() {
1433314346 await readFile(path.join(WIKI_PATH, baseSummaryFilename), "utf8")
1433414347 );
1433514348
14336- const diff = coverageDiff.diff (base, head);
14349+ const diff = computeDiff (base, head, { allowedToFail } );
1433714350
1433814351 if (issue_number) {
14339- await deleteExistingComments(
14340- octokit,
14341- context.repo,
14342- issue_number
14343- );
14352+ await deleteExistingComments(octokit, context.repo, issue_number);
1434414353
1434514354 core.info("Add a comment with the diff coverage report");
14346- await addComment(
14347- octokit,
14348- context.repo,
14349- issue_number,
14350- renderDiff(base, head, diff, { allowedToFail })
14351- );
14355+ await addComment(octokit, context.repo, issue_number, diff.markdown);
1435214356 } else {
1435314357 core.info(diff.results);
1435414358 }
1435514359
1435614360 if (!allowedToFail && diff.regression) {
14357- throw new Error("The coverage is below the minimum threshold ");
14361+ throw new Error("Total coverage is lower than the default branch ");
1435814362 }
1435914363 }
1436014364}
0 commit comments