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

Add input for skipping full covered files from xml #186

Merged
Merged
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 @@ -45,6 +45,7 @@ You can add this action to your GitHub workflow for Ubuntu runners (e.g. runs-on
| `junitxml-title` | | '' | Title for summary for junitxml |
| `create-new-comment` | | false | When false, will update the same comment, otherwise will publish new comment on each run. |
| `hide-comment` | | false | Hide the whole comment (use when you need only the `output`). Useful for auto-update bagdes in readme. See the [workflow](../main/.github/workflows/live-test.yml) for example |
| `xml-skip-covered` | | false | Hide files from xml report with 100% coverage |
| `default-branch` | | `main` | This branch name is useful when generate "coverageHtml", it points direct links to files on this branch (instead of commit).<br/>Usually "main" or "master" |
| `multiple-files` | | '' | You can pass array of titles and files to generate single comment with table of results.<br/>Single line should look like `Title, ./path/to/pytest-coverage.txt, ./path/to/pytest-junit.xml`<br/> example:<br/> `My Title 1, ./data/pytest-coverage_3.txt, ./data/pytest_1.xml`<br/>**Note:** In that mode the `output` for `coverage` and `color` will be for the first file only. |
| `remove-link-from-badge` | | false | When true, it will remove the link from badge to readme |
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ inputs:
default: 'false'
required: false

xml-skip-covered:
description: 'Hide files from xml report with 100% coverage.'
default: 'false'
required: false

report-only-changed-files:
description: 'Show in report only changed files for this commit, and not all files'
default: 'false'
Expand Down
18 changes: 11 additions & 7 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17396,7 +17396,7 @@ const getCoverageXmlReport = (options) => {
}

if (parsedXml && isValid) {
const coverageObj = coverageXmlToFiles(parsedXml);
const coverageObj = coverageXmlToFiles(parsedXml, options.xmlSkipCovered);
const dataFromXml = { coverage: coverageObj, total: coverage };
const html = toHtml(null, options, dataFromXml);
const color = getCoverageColor(coverage ? coverage.cover : '0');
Expand Down Expand Up @@ -17436,7 +17436,7 @@ const getXmlContent = (data) => {
};

// parse coverage xml to Files structure
const coverageXmlToFiles = (coverageXml) => {
const coverageXmlToFiles = (coverageXml, xmlSkipCovered) => {
let files = [];

coverageXml.packages[0].package
Expand All @@ -17445,7 +17445,7 @@ const coverageXmlToFiles = (coverageXml) => {
package.classes[0].class
.filter((c) => c.lines)
.forEach((c) => {
const fileObj = parseClass(c);
const fileObj = parseClass(c, xmlSkipCovered);

if (fileObj) {
files.push(fileObj);
Expand All @@ -17456,19 +17456,19 @@ const coverageXmlToFiles = (coverageXml) => {
return files;
};

const parseClass = (classObj) => {
const parseClass = (classObj, xmlSkipCovered) => {
if (!classObj || !classObj.lines) {
return null;
}

const { stmts, missing, totalMissing: miss } = parseLines(classObj.lines);
const { filename: name, 'line-rate': lineRate } = classObj['$'];

const isFullCoverage = lineRate === '1';
if (xmlSkipCovered && isFullCoverage) {
return null;
}
const cover = isFullCoverage
? '100%'
: `${parseInt(parseFloat(lineRate) * 100)}%`;

return { name, stmts, miss, cover, missing };
};

Expand Down Expand Up @@ -17875,6 +17875,9 @@ const main = async () => {
required: false,
});
const hideComment = core.getBooleanInput('hide-comment', { required: false });
const xmlSkipCovered = core.getBooleanInput('xml-skip-covered', {
required: false,
});
const reportOnlyChangedFiles = core.getBooleanInput(
'report-only-changed-files',
{ required: false },
Expand Down Expand Up @@ -17920,6 +17923,7 @@ const main = async () => {
hideReport,
createNewComment,
hideComment,
xmlSkipCovered,
reportOnlyChangedFiles,
removeLinkFromBadge,
defaultBranch,
Expand Down
1 change: 1 addition & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const main = async () => {
reportOnlyChangedFiles: false,
removeLinkFromBadge: false,
hideComment: false,
// xmlSkipCovered: true,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why commented?

xmlTitle: '',
// multipleFiles,
changedFiles: {
Expand Down
4 changes: 4 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ const main = async () => {
required: false,
});
const hideComment = core.getBooleanInput('hide-comment', { required: false });
const xmlSkipCovered = core.getBooleanInput('xml-skip-covered', {
required: false,
});
const reportOnlyChangedFiles = core.getBooleanInput(
'report-only-changed-files',
{ required: false },
Expand Down Expand Up @@ -108,6 +111,7 @@ const main = async () => {
hideReport,
createNewComment,
hideComment,
xmlSkipCovered,
reportOnlyChangedFiles,
removeLinkFromBadge,
defaultBranch,
Expand Down
14 changes: 7 additions & 7 deletions src/parseXml.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getCoverageXmlReport = (options) => {
}

if (parsedXml && isValid) {
const coverageObj = coverageXmlToFiles(parsedXml);
const coverageObj = coverageXmlToFiles(parsedXml, options.xmlSkipCovered);
const dataFromXml = { coverage: coverageObj, total: coverage };
const html = toHtml(null, options, dataFromXml);
const color = getCoverageColor(coverage ? coverage.cover : '0');
Expand Down Expand Up @@ -101,7 +101,7 @@ const getXmlContent = (data) => {
};

// parse coverage xml to Files structure
const coverageXmlToFiles = (coverageXml) => {
const coverageXmlToFiles = (coverageXml, xmlSkipCovered) => {
let files = [];

coverageXml.packages[0].package
Expand All @@ -110,7 +110,7 @@ const coverageXmlToFiles = (coverageXml) => {
package.classes[0].class
.filter((c) => c.lines)
.forEach((c) => {
const fileObj = parseClass(c);
const fileObj = parseClass(c, xmlSkipCovered);

if (fileObj) {
files.push(fileObj);
Expand All @@ -121,19 +121,19 @@ const coverageXmlToFiles = (coverageXml) => {
return files;
};

const parseClass = (classObj) => {
const parseClass = (classObj, xmlSkipCovered) => {
if (!classObj || !classObj.lines) {
return null;
}

const { stmts, missing, totalMissing: miss } = parseLines(classObj.lines);
const { filename: name, 'line-rate': lineRate } = classObj['$'];

const isFullCoverage = lineRate === '1';
if (xmlSkipCovered && isFullCoverage) {
return null;
}
const cover = isFullCoverage
? '100%'
: `${parseInt(parseFloat(lineRate) * 100)}%`;

return { name, stmts, miss, cover, missing };
};

Expand Down
Loading