Browse Source
* 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 /
2 changed files with 64 additions and 0 deletions
@ -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…
Reference in new issue