diff --git a/libs/index.md b/libs/index.md index 31046d6..86d8206 100644 --- a/libs/index.md +++ b/libs/index.md @@ -141,6 +141,12 @@ Available icons: ['coverage', '/codecov/c/github/tunnckoCore/gitcommit'], ['coverage (branch)', '/codecov/c/github/babel/babel/6.x'] ], + coveralls: [ + ['coverage (github)', '/coveralls/c/github/jekyll/jekyll'], + ['coverage (github, branch)', '/coveralls/c/github/jekyll/jekyll/master'], + ['coverage (bitbucket)', '/coveralls/c/bitbucket/pyKLIP/pyklip'], + ['coverage (bitbucket, branch)', '/coveralls/c/bitbucket/pyKLIP/pyklip/master'], + ], 'david-dm': [ ['dependencies', '/david/dep/zeit/pkg'], ['dev dependencies', '/david/dev/zeit/pkg'], diff --git a/libs/live-fns/_index.js b/libs/live-fns/_index.js index dbd5cfa..8ff48c5 100644 --- a/libs/live-fns/_index.js +++ b/libs/live-fns/_index.js @@ -5,6 +5,7 @@ module.exports = { 'chrome-web-store': require('./chrome-web-store.js'), 'circleci': require('./circleci.js'), 'codecov': require('./codecov.js'), + 'coveralls': require('./coveralls.js'), 'crates': require('./crates.js'), 'david': require('./david.js'), 'docker': require('./docker.js'), diff --git a/libs/live-fns/codecov.js b/libs/live-fns/codecov.js index dabec2e..2251c8b 100644 --- a/libs/live-fns/codecov.js +++ b/libs/live-fns/codecov.js @@ -1,4 +1,5 @@ const axios = require('../axios.js') +const covColor = require('../utils/cov-color.js') // https://codecov.io/gh/user/repo/settings/badge @@ -21,22 +22,6 @@ module.exports = async function codecov (topic, ...args) { } } -function getColor (value, orange = 70, yellow = 85, green = 100) { - if (value <= 0) { - return 'red' - } - if (value < orange) { - return 'ef6c00' - } - if (value < yellow) { - return 'c0ca33' - } - if (value < green) { - return 'a4a61d' - } - return 'green' -} - async function coverage (vscType, user, repo, branch) { branch = typeof branch === 'string' && branch.length > 0 ? branch : 'master' @@ -53,11 +38,9 @@ async function coverage (vscType, user, repo, branch) { } } - const color = getColor(+status) - return { subject: 'codecov', status: `${status}%`, - color + color: covColor(status) } } diff --git a/libs/live-fns/coveralls.js b/libs/live-fns/coveralls.js new file mode 100644 index 0000000..8dec10c --- /dev/null +++ b/libs/live-fns/coveralls.js @@ -0,0 +1,18 @@ +const axios = require('../axios.js') +const covColor = require('../utils/cov-color.js') + +module.exports = async function (topic, platform, user, repo, branch) { + // only support topic="c" fow now + + const query = branch ? `?branch=${branch}` : '' + const endpoint = `https://coveralls.io/${platform}/${user}/${repo}.json${query}` + + /* eslint-disable camelcase */ + const { covered_percent } = await axios.get(endpoint).then(res => res.data) + + return { + subject: 'coverage', + status: Number(covered_percent).toFixed(2) + '%', + color: covColor(covered_percent) + } +} diff --git a/libs/serve-index.js b/libs/serve-index.js index 1702fec..f374b60 100644 --- a/libs/serve-index.js +++ b/libs/serve-index.js @@ -25,7 +25,7 @@ module.exports = serveMarked('libs/index.md', { dt a:hover:before { left: -1.2em; font: 20px/20px Arial; vertical-align: middle; color: #CCC } dd { font: 14px/20px monospace; vertical-align: top; height: 28px; white-space: nowrap; margin: 0 } dd img { vertical-align: top } - dd b { display: inline-block; min-width: 14em; text-align: right; font-weight: 300 } + dd b { display: inline-block; min-width: 17em; text-align: right; font-weight: 300 } dd i { display: inline-block; min-width: 13em } `, beforeHeadEnd: ``, diff --git a/libs/utils/cov-color.js b/libs/utils/cov-color.js new file mode 100644 index 0000000..e1046da --- /dev/null +++ b/libs/utils/cov-color.js @@ -0,0 +1,24 @@ +/** + * Generate color from coverage number + * + * @param {Number} value + * @param {Number} orange + * @param {Number} yellow + * @param {Number} green + */ + +module.exports = function cc (value, orange = 70, yellow = 85, green = 100) { + if (value <= 0) { + return 'red' + } + if (value < orange) { + return 'ef6c00' + } + if (value < yellow) { + return 'c0ca33' + } + if (value < green) { + return 'a4a61d' + } + return 'green' +}