Browse Source

live-fns: add coveralls.js

test
Amio 6 years ago
parent
commit
c674af15fc
  1. 6
      libs/index.md
  2. 1
      libs/live-fns/_index.js
  3. 21
      libs/live-fns/codecov.js
  4. 18
      libs/live-fns/coveralls.js
  5. 2
      libs/serve-index.js
  6. 24
      libs/utils/cov-color.js

6
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'],

1
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'),

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

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

2
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: `<link rel="icon" type="image/svg+xml" href="/favicon.svg">`,

24
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'
}
Loading…
Cancel
Save