From d1f76f6aa608816b3e18d7d5041eec982503a265 Mon Sep 17 00:00:00 2001 From: Lewke Date: Sat, 5 Oct 2024 09:46:59 +0100 Subject: [PATCH] added ability to only show files not meeting minimum coverage --- README.md | 5 +++++ dist/index.js | 8 ++++++++ src/action.js | 8 ++++++++ src/action.test.js | 17 +++++++++++++++++ 4 files changed, 38 insertions(+) diff --git a/README.md b/README.md index ff497de7..d8ee590c 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,11 @@ Default is no crop. (Note: "…" is appended to a cropped string) +### `show_minimum_coverage_files` + +Show files that meet minimum coverage requirements +Defaults to `true` + ### `link_missing_lines` Link missing line numbers. This only has an effect when `show_missing` is set to `true`. diff --git a/dist/index.js b/dist/index.js index 98f945ec..678ec158 100644 --- a/dist/index.js +++ b/dist/index.js @@ -38908,6 +38908,9 @@ async function action(payload) { showMissingMaxLength = showMissingMaxLength ? parseInt(showMissingMaxLength) : -1; + const showMinimumCoverageFiles = JSON.parse( + core.getInput("show_minimum_coverage_files", { required: false }) || "true", + ); const linkMissingLines = JSON.parse( core.getInput("link_missing_lines", { required: false }) || "false", ); @@ -38930,6 +38933,7 @@ async function action(payload) { showClassNames, showMissing, showMissingMaxLength, + showMinimumCoverageFiles, linkMissingLines, linkMissingLinesSourceDir, filteredFiles: changedFiles, @@ -39024,6 +39028,7 @@ function markdownReport(reports, commit, options) { showClassNames = false, showMissing = false, showMissingMaxLength = -1, + showMinimumCoverageFiles = true, linkMissingLines = false, linkMissingLinesSourceDir = null, filteredFiles = null, @@ -39042,6 +39047,9 @@ function markdownReport(reports, commit, options) { const fileTotal = Math.floor(file.total); const fileLines = Math.floor(file.line); const fileBranch = Math.floor(file.branch); + if (!showMinimumCoverageFiles && fileTotal > minimumCoverage) { + continue; + } files.push([ escapeMarkdown(showClassNames ? file.name : file.filename), `\`${fileTotal}%\``, diff --git a/src/action.js b/src/action.js index ba6324b0..e59eef7a 100644 --- a/src/action.js +++ b/src/action.js @@ -41,6 +41,9 @@ async function action(payload) { showMissingMaxLength = showMissingMaxLength ? parseInt(showMissingMaxLength) : -1; + const showMinimumCoverageFiles = JSON.parse( + core.getInput("show_minimum_coverage_files", { required: false }) || "true", + ); const linkMissingLines = JSON.parse( core.getInput("link_missing_lines", { required: false }) || "false", ); @@ -63,6 +66,7 @@ async function action(payload) { showClassNames, showMissing, showMissingMaxLength, + showMinimumCoverageFiles, linkMissingLines, linkMissingLinesSourceDir, filteredFiles: changedFiles, @@ -157,6 +161,7 @@ function markdownReport(reports, commit, options) { showClassNames = false, showMissing = false, showMissingMaxLength = -1, + showMinimumCoverageFiles = true, linkMissingLines = false, linkMissingLinesSourceDir = null, filteredFiles = null, @@ -175,6 +180,9 @@ function markdownReport(reports, commit, options) { const fileTotal = Math.floor(file.total); const fileLines = Math.floor(file.line); const fileBranch = Math.floor(file.branch); + if (!showMinimumCoverageFiles && fileTotal > minimumCoverage) { + continue; + } files.push([ escapeMarkdown(showClassNames ? file.name : file.filename), `\`${fileTotal}%\``, diff --git a/src/action.test.js b/src/action.test.js index 0bc3dcaf..e16e3e97 100644 --- a/src/action.test.js +++ b/src/action.test.js @@ -720,6 +720,23 @@ _Minimum allowed coverage is \`100%\`_ _Minimum allowed coverage is \`100%\`_ +

Generated by :monkey: cobertura-action against deadbeef

`); + + expect( + markdownReport([dummyReport], commit, { + minimumCoverage: 76, + showMinimumCoverageFiles: false, + }), + ).toBe(`${defaultReportName} + +| File | Coverage | | +| - | :-: | :-: | +| **All files** | \`77%\` | :white_check_mark: | +| bar.py | \`75%\` | :x: | +| foo.py | \`75%\` | :x: | + +_Minimum allowed coverage is \`76%\`_ +

Generated by :monkey: cobertura-action against deadbeef

`); });