live-fns: add coveralls.js

pull/51/head
Amio 2018-07-30 17:15:48 +08:00
rodzic dbf5850042
commit c674af15fc
6 zmienionych plików z 52 dodań i 20 usunięć

Wyświetl plik

@ -141,6 +141,12 @@ Available icons:
['coverage', '/codecov/c/github/tunnckoCore/gitcommit'], ['coverage', '/codecov/c/github/tunnckoCore/gitcommit'],
['coverage (branch)', '/codecov/c/github/babel/babel/6.x'] ['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': [ 'david-dm': [
['dependencies', '/david/dep/zeit/pkg'], ['dependencies', '/david/dep/zeit/pkg'],
['dev dependencies', '/david/dev/zeit/pkg'], ['dev dependencies', '/david/dev/zeit/pkg'],

Wyświetl plik

@ -5,6 +5,7 @@ module.exports = {
'chrome-web-store': require('./chrome-web-store.js'), 'chrome-web-store': require('./chrome-web-store.js'),
'circleci': require('./circleci.js'), 'circleci': require('./circleci.js'),
'codecov': require('./codecov.js'), 'codecov': require('./codecov.js'),
'coveralls': require('./coveralls.js'),
'crates': require('./crates.js'), 'crates': require('./crates.js'),
'david': require('./david.js'), 'david': require('./david.js'),
'docker': require('./docker.js'), 'docker': require('./docker.js'),

Wyświetl plik

@ -1,4 +1,5 @@
const axios = require('../axios.js') const axios = require('../axios.js')
const covColor = require('../utils/cov-color.js')
// https://codecov.io/gh/user/repo/settings/badge // 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) { async function coverage (vscType, user, repo, branch) {
branch = typeof branch === 'string' && branch.length > 0 ? branch : 'master' 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 { return {
subject: 'codecov', subject: 'codecov',
status: `${status}%`, status: `${status}%`,
color color: covColor(status)
} }
} }

Wyświetl plik

@ -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)
}
}

Wyświetl plik

@ -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 } 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 { font: 14px/20px monospace; vertical-align: top; height: 28px; white-space: nowrap; margin: 0 }
dd img { vertical-align: top } 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 } dd i { display: inline-block; min-width: 13em }
`, `,
beforeHeadEnd: `<link rel="icon" type="image/svg+xml" href="/favicon.svg">`, beforeHeadEnd: `<link rel="icon" type="image/svg+xml" href="/favicon.svg">`,

Wyświetl plik

@ -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'
}