Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 18 improvement add option to hide details #20

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
56 changes: 33 additions & 23 deletions dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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,
Expand All @@ -6050,22 +6051,27 @@ function commentForMonorepo(
? th(arrow, " ", plus, pdiff.toFixed(2), "%")
: "";

return `${table(
const coverageTable = table(
tbody(
tr(
th(lcovObj.packageName),
th(percentage(lcovObj.lcov).toFixed(2), "%"),
pdiffHtml,
),
),
)} \n\n ${details(
summary("Coverage Report"),
tabulate(lcovObj.lcov, options),
)} <br/>`;
);
const detailsTable = !hideDetails
? `\n\n ${details(
summary("Coverage Report"),
tabulate(lcovObj.lcov, options),
)} <br/>`
: "";

return `${coverageTable} ${detailsTable}`.trim();
});

return fragment(
`Coverage after merging into ${b(options.base)} <p></p>`,
`Coverage after merging into ${b(base)} <p></p>`,
html.join(""),
);
}
Expand All @@ -6081,17 +6087,19 @@ 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,
)} <p></p>`,
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)}<p></p>`;
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);
}

/**
Expand Down Expand Up @@ -6217,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;
};

Expand All @@ -6239,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;
};

Expand All @@ -6256,6 +6262,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");

Expand All @@ -6264,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;
}

Expand All @@ -6274,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)
: [];

Expand Down Expand Up @@ -6309,6 +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,
};

const lcov = !monorepoBasePath && (await parse$1(raw));
Expand All @@ -6330,7 +6340,7 @@ async function main() {
});
}

main().catch(function(err) {
main().catch(err => {
console.log(err);
core$1.setFailed(err.message);
});
34 changes: 21 additions & 13 deletions src/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -28,22 +29,27 @@ export function commentForMonorepo(
? th(arrow, " ", plus, pdiff.toFixed(2), "%")
: "";

return `${table(
const coverageTable = table(
tbody(
tr(
th(lcovObj.packageName),
th(percentage(lcovObj.lcov).toFixed(2), "%"),
pdiffHtml,
),
),
)} \n\n ${details(
summary("Coverage Report"),
tabulate(lcovObj.lcov, options),
)} <br/>`;
);
const detailsTable = !hideDetails
? `\n\n ${details(
summary("Coverage Report"),
tabulate(lcovObj.lcov, options),
)} <br/>`
: "";

return `${coverageTable} ${detailsTable}`.trim();
});

return fragment(
`Coverage after merging into ${b(options.base)} <p></p>`,
`Coverage after merging into ${b(base)} <p></p>`,
html.join(""),
);
}
Expand All @@ -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,
)} <p></p>`,
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)}<p></p>`;
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);
}

/**
Expand Down
22 changes: 12 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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;
};

Expand All @@ -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;
};

Expand All @@ -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");

Expand All @@ -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;
}

Expand All @@ -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)
: [];

Expand Down Expand Up @@ -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));
Expand All @@ -130,7 +132,7 @@ async function main() {
});
}

main().catch(function(err) {
main().catch(err => {
console.log(err);
core.setFailed(err.message);
});