From bf85e0d27d964a47458d02a5d8e0116d1a7c6b8f Mon Sep 17 00:00:00 2001 From: Janos Szathmary Date: Fri, 5 Feb 2021 11:11:02 +0100 Subject: [PATCH 1/2] ISSUE-18 add option to hide details --- README.md | 1 + action.yml | 3 +++ dist/main.js | 36 +++++++++++++++--------------------- src/comment.js | 34 +++++++++++++++++++++------------- src/index.js | 22 ++++++++++++---------- 5 files changed, 52 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index 955d64ec..d5cac278 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ The possible inputs for this action are: | `monorepo-base-path` (**Optional**) | The location of your monrepo `packages` path | | | `lcov-file` (**Optional**) | The location of the lcov file to read the coverage report. `Needed only for single repos` | `./coverage/lcov.info` | | `lcov-base` (**Optional**) | The location of the lcov file resulting from running the tests in the base branch. When this is set a diff of the coverage percentages is shown. `Needed only for single repos`. | | +| `hide-details` (**Optional**) | Flag to optionally hide coverage details, this feature is useful for big repositories with lots of files. | `false` | ## Examples diff --git a/action.yml b/action.yml index 963c3d36..955a0cbd 100644 --- a/action.yml +++ b/action.yml @@ -17,6 +17,9 @@ inputs: lcov-base: description: The location of the lcov file for the base branch. Applicable for single repo setup. required: false + hide-details: + description: Flag to optionally hide coverage details, this feature is useful for big repositories with lots of files. + required: false runs: using: node12 main: dist/main.js diff --git a/dist/main.js b/dist/main.js index a1cd21b6..3e800dac 100644 --- a/dist/main.js +++ b/dist/main.js @@ -6035,6 +6035,7 @@ function commentForMonorepo( lcovBaseArrayForMonorepo, options, ) { + const { hideDetails, base } = options; const html = lcovArrayForMonorepo.map(lcovObj => { const baseLcov = lcovBaseArrayForMonorepo.find( el => el.packageName === lcovObj.packageName, @@ -6050,22 +6051,14 @@ function commentForMonorepo( ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return `${table( - tbody( - tr( - th(lcovObj.packageName), - th(percentage(lcovObj.lcov).toFixed(2), "%"), - pdiffHtml, - ), - ), - )} \n\n ${details( - summary("Coverage Report"), - tabulate(lcovObj.lcov, options), - )}
`; + const coverageTable = table(tbody(tr(th(lcovObj.packageName), th(percentage(lcovObj.lcov).toFixed(2), "%"), pdiffHtml,))); + const detailsTable = !hideDetails ? `\n\n ${details(summary("Coverage Report"), tabulate(lcovObj.lcov, options))}
` : ""; + + return `${coverageTable} ${detailsTable}`.trim(); }); return fragment( - `Coverage after merging into ${b(options.base)}

`, + `Coverage after merging into ${b(base)}

`, html.join(""), ); } @@ -6081,17 +6074,15 @@ function comment(lcov, before, options) { const pdiff = pafter - pbefore; const plus = pdiff > 0 ? "+" : ""; const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴"; + const { hideDetails, base } = options; const pdiffHtml = before ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return fragment( - `Coverage after merging ${b(options.head)} into ${b( - options.base, - )}

`, - table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))), - "\n\n", - details(summary("Coverage Report"), tabulate(lcov, options)), - ); + const title = `Coverage after merging into ${b(base,)}

`; + const coverageTable = table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))); + const detailsTable = !hideDetails ? `\n\n ${details(summary("Coverage Report"), tabulate(lcov, options))}` : ""; + + return fragment(title, coverageTable, detailsTable); } /** @@ -6256,6 +6247,8 @@ async function main() { const token = core$1.getInput("github-token"); const lcovFile = core$1.getInput("lcov-file") || "./coverage/lcov.info"; const baseFile = core$1.getInput("lcov-base"); + const hideDetails = !!core$1.getInput("hide-details"); + // Add base path for monorepo const monorepoBasePath = core$1.getInput("monorepo-base-path"); @@ -6309,6 +6302,7 @@ async function main() { prefix: `${process.env.GITHUB_WORKSPACE}/`, head: context.payload.pull_request.head.ref, base: context.payload.pull_request.base.ref, + hideDetails }; const lcov = !monorepoBasePath && (await parse$1(raw)); diff --git a/src/comment.js b/src/comment.js index 96ed1da0..abe6fe61 100644 --- a/src/comment.js +++ b/src/comment.js @@ -13,6 +13,7 @@ export function commentForMonorepo( lcovBaseArrayForMonorepo, options, ) { + const { hideDetails, base } = options; const html = lcovArrayForMonorepo.map(lcovObj => { const baseLcov = lcovBaseArrayForMonorepo.find( el => el.packageName === lcovObj.packageName, @@ -28,7 +29,7 @@ export function commentForMonorepo( ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return `${table( + const coverageTable = table( tbody( tr( th(lcovObj.packageName), @@ -36,14 +37,19 @@ export function commentForMonorepo( pdiffHtml, ), ), - )} \n\n ${details( - summary("Coverage Report"), - tabulate(lcovObj.lcov, options), - )}
`; + ); + const detailsTable = !hideDetails + ? `\n\n ${details( + summary("Coverage Report"), + tabulate(lcovObj.lcov, options), + )}
` + : ""; + + return `${coverageTable} ${detailsTable}`.trim(); }); return fragment( - `Coverage after merging into ${b(options.base)}

`, + `Coverage after merging into ${b(base)}

`, html.join(""), ); } @@ -59,17 +65,19 @@ export function comment(lcov, before, options) { const pdiff = pafter - pbefore; const plus = pdiff > 0 ? "+" : ""; const arrow = pdiff === 0 ? "" : pdiff < 0 ? "▾" : "▴"; + const { hideDetails, base } = options; const pdiffHtml = before ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - return fragment( - `Coverage after merging ${b(options.head)} into ${b( - options.base, - )}

`, - table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))), - "\n\n", - details(summary("Coverage Report"), tabulate(lcov, options)), + const title = `Coverage after merging into ${b(base)}

`; + const coverageTable = table( + tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml)), ); + const detailsTable = !hideDetails + ? `\n\n ${details(summary("Coverage Report"), tabulate(lcov, options))}` + : ""; + + return fragment(title, coverageTable, detailsTable); } /** diff --git a/src/index.js b/src/index.js index 6e1cc294..9e89a153 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import fs, { promises } from "fs"; +import path from "path"; import core from "@actions/core"; import github from "@actions/github"; -import path from "path"; import { parse } from "./lcov"; import { diff, diffForMonorepo } from "./comment"; import { upsertComment } from "./github"; @@ -17,14 +17,13 @@ const getLcovFiles = (dir, filelist = []) => { filelist = fs.statSync(path.join(dir, file)).isDirectory() ? getLcovFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov.info"); - }) + .filter(file => file.path.includes("lcov.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -39,14 +38,13 @@ const getLcovBaseFiles = (dir, filelist = []) => { filelist = fs.statSync(path.join(dir, file)).isDirectory() ? getLcovBaseFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov-base.info"); - }) + .filter(file => file.path.includes("lcov-base.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -56,6 +54,8 @@ async function main() { const token = core.getInput("github-token"); const lcovFile = core.getInput("lcov-file") || "./coverage/lcov.info"; const baseFile = core.getInput("lcov-base"); + const hideDetails = !!core.getInput("hide-details"); + // Add base path for monorepo const monorepoBasePath = core.getInput("monorepo-base-path"); @@ -64,6 +64,7 @@ async function main() { (await promises.readFile(lcovFile, "utf-8").catch(err => null)); if (!monorepoBasePath && !raw) { console.log(`No coverage report found at '${lcovFile}', exiting...`); + return; } @@ -74,8 +75,8 @@ async function main() { console.log(`No coverage report found at '${baseFile}', ignoring...`); } - let lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; - let lcovBaseArray = monorepoBasePath + const lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; + const lcovBaseArray = monorepoBasePath ? getLcovBaseFiles(monorepoBasePath) : []; @@ -109,6 +110,7 @@ async function main() { prefix: `${process.env.GITHUB_WORKSPACE}/`, head: context.payload.pull_request.head.ref, base: context.payload.pull_request.base.ref, + hideDetails, }; const lcov = !monorepoBasePath && (await parse(raw)); @@ -130,7 +132,7 @@ async function main() { }); } -main().catch(function(err) { +main().catch(err => { console.log(err); core.setFailed(err.message); }); From 94ad383d1418c2d9f45cd4b24f4cdc6e59294e2a Mon Sep 17 00:00:00 2001 From: Janos Szathmary Date: Fri, 5 Feb 2021 11:11:18 +0100 Subject: [PATCH 2/2] ISSUE-18 add option to hide details --- dist/main.js | 50 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/dist/main.js b/dist/main.js index 3e800dac..70db6bf9 100644 --- a/dist/main.js +++ b/dist/main.js @@ -4,8 +4,8 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau var fs = require('fs'); var fs__default = _interopDefault(fs); -var os = _interopDefault(require('os')); var path = _interopDefault(require('path')); +var os = _interopDefault(require('os')); var http = _interopDefault(require('http')); var https = _interopDefault(require('https')); require('net'); @@ -6035,7 +6035,7 @@ function commentForMonorepo( lcovBaseArrayForMonorepo, options, ) { - const { hideDetails, base } = options; + const { hideDetails, base } = options; const html = lcovArrayForMonorepo.map(lcovObj => { const baseLcov = lcovBaseArrayForMonorepo.find( el => el.packageName === lcovObj.packageName, @@ -6051,8 +6051,21 @@ function commentForMonorepo( ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - const coverageTable = table(tbody(tr(th(lcovObj.packageName), th(percentage(lcovObj.lcov).toFixed(2), "%"), pdiffHtml,))); - const detailsTable = !hideDetails ? `\n\n ${details(summary("Coverage Report"), tabulate(lcovObj.lcov, options))}
` : ""; + const coverageTable = table( + tbody( + tr( + th(lcovObj.packageName), + th(percentage(lcovObj.lcov).toFixed(2), "%"), + pdiffHtml, + ), + ), + ); + const detailsTable = !hideDetails + ? `\n\n ${details( + summary("Coverage Report"), + tabulate(lcovObj.lcov, options), + )}
` + : ""; return `${coverageTable} ${detailsTable}`.trim(); }); @@ -6078,9 +6091,13 @@ function comment(lcov, before, options) { const pdiffHtml = before ? th(arrow, " ", plus, pdiff.toFixed(2), "%") : ""; - const title = `Coverage after merging into ${b(base,)}

`; - const coverageTable = table(tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml))); - const detailsTable = !hideDetails ? `\n\n ${details(summary("Coverage Report"), tabulate(lcov, options))}` : ""; + const title = `Coverage after merging into ${b(base)}

`; + const coverageTable = table( + tbody(tr(th(percentage(lcov).toFixed(2), "%"), pdiffHtml)), + ); + const detailsTable = !hideDetails + ? `\n\n ${details(summary("Coverage Report"), tabulate(lcov, options))}` + : ""; return fragment(title, coverageTable, detailsTable); } @@ -6208,14 +6225,13 @@ const getLcovFiles = (dir, filelist = []) => { filelist = fs__default.statSync(path.join(dir, file)).isDirectory() ? getLcovFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov.info"); - }) + .filter(file => file.path.includes("lcov.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -6230,14 +6246,13 @@ const getLcovBaseFiles = (dir, filelist = []) => { filelist = fs__default.statSync(path.join(dir, file)).isDirectory() ? getLcovBaseFiles(path.join(dir, file), filelist) : filelist - .filter(file => { - return file.path.includes("lcov-base.info"); - }) + .filter(file => file.path.includes("lcov-base.info")) .concat({ name: dir.split("/")[1], path: path.join(dir, file), }); }); + return filelist; }; @@ -6257,6 +6272,7 @@ async function main() { (await fs.promises.readFile(lcovFile, "utf-8").catch(err => null)); if (!monorepoBasePath && !raw) { console.log(`No coverage report found at '${lcovFile}', exiting...`); + return; } @@ -6267,8 +6283,8 @@ async function main() { console.log(`No coverage report found at '${baseFile}', ignoring...`); } - let lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; - let lcovBaseArray = monorepoBasePath + const lcovArray = monorepoBasePath ? getLcovFiles(monorepoBasePath) : []; + const lcovBaseArray = monorepoBasePath ? getLcovBaseFiles(monorepoBasePath) : []; @@ -6302,7 +6318,7 @@ async function main() { prefix: `${process.env.GITHUB_WORKSPACE}/`, head: context.payload.pull_request.head.ref, base: context.payload.pull_request.base.ref, - hideDetails + hideDetails, }; const lcov = !monorepoBasePath && (await parse$1(raw)); @@ -6324,7 +6340,7 @@ async function main() { }); } -main().catch(function(err) { +main().catch(err => { console.log(err); core$1.setFailed(err.message); });