Skip to content

Instantly share code, notes, and snippets.

@ericduran
Last active March 24, 2019 01:39
Show Gist options
  • Save ericduran/8066196c9a3eb0e9e2401887858fc42c to your computer and use it in GitHub Desktop.
Save ericduran/8066196c9a3eb0e9e2401887858fc42c to your computer and use it in GitHub Desktop.
/**
* Generates a msg with the Coverage Difference.
* We used this output to generate a GH comment with the info.
*
* usage:
* node coveralls.js 31.3%
* node coveralls.js 34.3%
*/
var fs = require('fs');
var args = process.argv.slice(2);
var CURRENT_COVERAGE = '/var/lib/jenkins/.current-coverage.txt';
var IMAGE = "![Coverage Status](https://img.shields.io/badge/Coverage-%d%%-yellow.svg)";
var msg = '';
var diff = '';
try {
fs.lstatSync(CURRENT_COVERAGE);
}
catch (e) {
console.log("ERROR: " + CURRENT_COVERAGE + " doesn't exist.");
process.exit()
}
var current = fs.readFileSync(CURRENT_COVERAGE, 'utf8').replace("%", "").trim();
var pr_covs = args[0].replace("%", "").trim();
if (current == pr_covs) {
msg = "Coverage remained the same at %d%%." + IMAGE;
diff = pr_covs;
}
if (current > pr_covs) {
msg = "Coverage decreased (-%d%%)." + IMAGE;
diff = (current - pr_covs).toFixed(2);
}
if (current < pr_covs) {
msg = "Coverage increased (+%d%%)." + IMAGE;
diff = (pr_covs - current).toFixed(2);
}
console.log(msg, diff, pr_covs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment