Skip to content

Commit

Permalink
Bump version to 1.3 (#41)
Browse files Browse the repository at this point in the history
* Refactor code

* Update CHANGELOG

* Build action

* Try N/A metric

* Revert "Try N/A metric"

This reverts commit bc51121.

* Add screenshot to README
  • Loading branch information
slavcodev committed Feb 19, 2022
1 parent 14fdbd1 commit e79a549
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# For local environment files use global ignore.

# Node modules
/node_modules/
/node_modules/
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ Security - in case of vulnerabilities.

_TBD_

## [1.3.0] 2021-01-29
## [1.3.0] 2022-02-19

### Added

- Added `threshold_metric` string property, the metric which should be considered, when calculating level.

### Change
### Changed

- Updated the table to include all 4 metics.
- Updated GitHub toolkit packages, fixed vulnerabilities alerts.
- Updated the table to include all 4 metrics.
- Updated comment table to show `N/A` if metric was not found in coverage file.

## [1.2.0] 2020-09-08

Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ jobs:
threshold_metric: "lines"
~~~

## Demo
## Preview

See [Pull Request #1](https://github.com/slavcodev/coverage-monitor-action/pull/1)
[![Screenshot][img-screenshot]][link-example-pr]

[img-screenshot]: screenshot.png
[link-example-pr]: https://github.com/slavcodev/coverage-monitor-action/pull/1

## Contributing

Expand Down
52 changes: 31 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12967,10 +12967,20 @@ async function readFile(filename) {
return parser.parseStringPromise(await fs.readFileAsync(filename));
}

function toBool(value) {
return typeof value === 'boolean'
? value
: value === 'true';
}

function toNumber(value) {
return value * 1;
}

function calcMetric(total, covered) {
const available = total > 0 && covered > 0;
const rate = total
? Number((covered / total) * 100).toFixed(2) * 1
? toNumber(Number((covered / total) * 100).toFixed(2))
: 0;

return {
Expand All @@ -12986,13 +12996,13 @@ function calculateLevel(metric, {
thresholdWarning = DEFAULT_THRESHOLD_WARNING,
thresholdMetric = DEFAULT_THRESHOLD_METRIC,
} = {}) {
const { rate: linesRate } = metric[thresholdMetric];
const { rate } = metric[thresholdMetric];

if (linesRate < thresholdAlert) {
if (rate < thresholdAlert) {
return 'red';
}

if (linesRate < thresholdWarning) {
if (rate < thresholdWarning) {
return 'yellow';
}

Expand All @@ -13004,12 +13014,22 @@ function readMetric(coverage, {
thresholdWarning = DEFAULT_THRESHOLD_WARNING,
thresholdMetric = DEFAULT_THRESHOLD_METRIC,
} = {}) {
const data = coverage.coverage.project[0].metrics[0].$;
const {
elements,
coveredelements,
statements,
coveredstatements,
methods,
coveredmethods,
conditionals,
coveredconditionals,
} = coverage.coverage.project[0].metrics[0].$;

const metric = {
statements: calcMetric(data.elements * 1, data.coveredelements * 1),
lines: calcMetric(data.statements * 1, data.coveredstatements * 1),
methods: calcMetric(data.methods * 1, data.coveredmethods * 1),
branches: calcMetric(data.conditionals * 1, data.coveredconditionals * 1),
statements: calcMetric(toNumber(elements), toNumber(coveredelements)),
lines: calcMetric(toNumber(statements), toNumber(coveredstatements)),
methods: calcMetric(toNumber(methods), toNumber(coveredmethods)),
branches: calcMetric(toNumber(conditionals), toNumber(coveredconditionals)),
};

metric.level = calculateLevel(metric, { thresholdAlert, thresholdWarning, thresholdMetric });
Expand Down Expand Up @@ -13092,23 +13112,13 @@ function generateStatus({
};
}

function toBool(value) {
return typeof value === 'boolean'
? value
: value === 'true';
}

function toInt(value) {
return value * 1;
}

function loadConfig({ getInput }) {
const comment = toBool(getInput('comment'));
const check = toBool(getInput('check'));
const githubToken = getInput('github_token', { required: true });
const cloverFile = getInput('clover_file', { required: true });
const thresholdAlert = toInt(getInput('threshold_alert') || 90);
const thresholdWarning = toInt(getInput('threshold_warning') || 50);
const thresholdAlert = toNumber(getInput('threshold_alert') || 90);
const thresholdWarning = toNumber(getInput('threshold_warning') || 50);
const statusContext = getInput('status_context') || 'Coverage Report';
const commentContext = getInput('comment_context') || 'Coverage Report';
let commentMode = getInput('comment_mode');
Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 31 additions & 21 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,20 @@ async function readFile(filename) {
return parser.parseStringPromise(await fs.readFileAsync(filename));
}

function toBool(value) {
return typeof value === 'boolean'
? value
: value === 'true';
}

function toNumber(value) {
return value * 1;
}

function calcMetric(total, covered) {
const available = total > 0 && covered > 0;
const rate = total
? Number((covered / total) * 100).toFixed(2) * 1
? toNumber(Number((covered / total) * 100).toFixed(2))
: 0;

return {
Expand All @@ -42,13 +52,13 @@ function calculateLevel(metric, {
thresholdWarning = DEFAULT_THRESHOLD_WARNING,
thresholdMetric = DEFAULT_THRESHOLD_METRIC,
} = {}) {
const { rate: linesRate } = metric[thresholdMetric];
const { rate } = metric[thresholdMetric];

if (linesRate < thresholdAlert) {
if (rate < thresholdAlert) {
return 'red';
}

if (linesRate < thresholdWarning) {
if (rate < thresholdWarning) {
return 'yellow';
}

Expand All @@ -60,12 +70,22 @@ function readMetric(coverage, {
thresholdWarning = DEFAULT_THRESHOLD_WARNING,
thresholdMetric = DEFAULT_THRESHOLD_METRIC,
} = {}) {
const data = coverage.coverage.project[0].metrics[0].$;
const {
elements,
coveredelements,
statements,
coveredstatements,
methods,
coveredmethods,
conditionals,
coveredconditionals,
} = coverage.coverage.project[0].metrics[0].$;

const metric = {
statements: calcMetric(data.elements * 1, data.coveredelements * 1),
lines: calcMetric(data.statements * 1, data.coveredstatements * 1),
methods: calcMetric(data.methods * 1, data.coveredmethods * 1),
branches: calcMetric(data.conditionals * 1, data.coveredconditionals * 1),
statements: calcMetric(toNumber(elements), toNumber(coveredelements)),
lines: calcMetric(toNumber(statements), toNumber(coveredstatements)),
methods: calcMetric(toNumber(methods), toNumber(coveredmethods)),
branches: calcMetric(toNumber(conditionals), toNumber(coveredconditionals)),
};

metric.level = calculateLevel(metric, { thresholdAlert, thresholdWarning, thresholdMetric });
Expand Down Expand Up @@ -148,23 +168,13 @@ function generateStatus({
};
}

function toBool(value) {
return typeof value === 'boolean'
? value
: value === 'true';
}

function toInt(value) {
return value * 1;
}

function loadConfig({ getInput }) {
const comment = toBool(getInput('comment'));
const check = toBool(getInput('check'));
const githubToken = getInput('github_token', { required: true });
const cloverFile = getInput('clover_file', { required: true });
const thresholdAlert = toInt(getInput('threshold_alert') || 90);
const thresholdWarning = toInt(getInput('threshold_warning') || 50);
const thresholdAlert = toNumber(getInput('threshold_alert') || 90);
const thresholdWarning = toNumber(getInput('threshold_warning') || 50);
const statusContext = getInput('status_context') || 'Coverage Report';
const commentContext = getInput('comment_context') || 'Coverage Report';
let commentMode = getInput('comment_mode');
Expand Down
Loading

0 comments on commit e79a549

Please sign in to comment.