Last active
March 24, 2019 01:39
-
-
Save ericduran/8066196c9a3eb0e9e2401887858fc42c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 = ""; | |
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