Browse Source

feat: add support for codecov coverage (#16)

* feat: add support for codecov coverage

Signed-off-by: Charlike Mike Reagent <olsten.larck@gmail.com>

* fix: ensurance for coverage loading

Signed-off-by: Charlike Mike Reagent <olsten.larck@gmail.com>

* chore: remove eslintConfig field

Signed-off-by: Charlike Mike Reagent <olsten.larck@gmail.com>

* fix: codecov badge when unknown repo

Signed-off-by: Charlike Mike Reagent <olsten.larck@gmail.com>

* fix: more safety cast result to string

Signed-off-by: Charlike Mike Reagent <olsten.larck@gmail.com>
test
Fox George Penguin 6 years ago
committed by Amio /
parent
commit
317d12313b
  1. 1
      libs/live-fns/_index.js
  2. 63
      libs/live-fns/codecov.js

1
libs/live-fns/_index.js

@ -1,4 +1,5 @@
module.exports = {
'codecov': require('./codecov.js'),
'appveyor': require('./appveyor.js'),
'chrome-web-store': require('./chrome-web-store.js'),
'circleci': require('./circleci.js'),

63
libs/live-fns/codecov.js

@ -0,0 +1,63 @@
const axios = require('../axios.js')
// https://codecov.io/gh/user/repo/settings/badge
/**
* `gh` is alias for `github` set by CodeCov
* badgen.now.sh/codecov/c/gh/amio/badgen
* badgen.now.sh/codecov/c/gh/amio/badgen/master
*/
module.exports = async function codecov (method, ...args) {
switch (method) {
case 'c': {
return coverage(...args)
}
default:
return {
subject: 'codecov',
status: 'unknown',
color: 'grey'
}
}
}
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'
const args = [vscType, user, repo, 'branch', branch]
const endpoint = `https://codecov.io/${args.join('/')}/graph/badge.txt`
const status = String(await axios.get(endpoint).then(res => res.data)).trim()
if (status === 'unknown') {
return {
subject: 'codecov',
status: 'unknown',
color: 'grey'
}
}
const color = getColor(+status)
return {
subject: 'codecov',
status: `${status}%`,
color
}
}
Loading…
Cancel
Save