Skip to content

Commit

Permalink
refactor: rename parse method, set failed on main flow
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvinwieth committed Oct 19, 2023
1 parent c8b3680 commit 9de0876
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ function run() {
const minCoverageInput = core.getInput('min_coverage');
const excluded = core.getInput('exclude');
const excludedFiles = excluded.split(' ');
const minCoverage = parseMinCoverage(minCoverageInput);
const minCoverage = tryParseMinCoverage(minCoverageInput);

if (minCoverage === null || !canParse(lcovPath)) {
if (minCoverage === null) {
core.setFailed(
'❌ Failed to parse min_coverage. Make sure to enter a valid number between 0 and 100.',
);
return;
}

if (!canParse(lcovPath)) {
return;
}

Expand Down Expand Up @@ -108,17 +115,14 @@ you have no test files or your tests are not generating any coverage data.
return true;
}

function parseMinCoverage(input) {
function tryParseMinCoverage(input) {
if (input === '') {
return 100;
}

const minCoverage = Number(input);

if (isNaN(minCoverage) || minCoverage < 0 || minCoverage > 100) {
core.setFailed(
'❌ Failed to parse min_coverage. Make sure to enter a valid number between 0 and 100.',
);
return null;
}

Expand Down

0 comments on commit 9de0876

Please sign in to comment.