Amio 2018-08-08 21:43:56 +08:00
commit b622854ead
9 zmienionych plików z 157 dodań i 110 usunięć

5
LICENSE.md 100644
Wyświetl plik

@ -0,0 +1,5 @@
Copyright 2018 Amio
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Wyświetl plik

@ -1,11 +1,11 @@
# Badgen Service
![License ISC](https://badgen.net/badge/license/ISC)
[![Uptime last week][uptime-src]][uptime-href]
[![Response time][response-src]][uptime-href]
[![Dependencies][dependencies-src]][dependencies-href]
[![License][license-src]][license-href]
[![StandardJS][standard-src]][standard-href]
[![dependencies][dep-src]][dep-href]
[![uptime past week][uptime-src]][uptime-href]
[![response time][response-src]][uptime-href]
[![deploy to now][deploy-to-now]](#deploy-to-now-cloud)
[![Deploy to now][deploy-to-now-src]](#deploy-to-now)
Home of [badgen.net](https://badgen.net), fast badge generating service.
@ -13,7 +13,7 @@ Home of [badgen.net](https://badgen.net), fast badge generating service.
- Written in latest, vanilla JavaScript => no build process
- Using [badgen](https://github.com/amio/badgen) library to generate svg on the fly => fast & stateless
- Hosted on [Now Cloud][now-href], serving behind Now CDN => faster & reliable
- Hosted on [Now][now-href], serving behind Now CDN => faster & reliable
- Cache less than 4 minutes => fresh & hot
- Three endpoints in one server
- https://badgen.net - classic style badges
@ -43,9 +43,9 @@ To ensure that your addition is working correctly start the development server w
Badgen Server will auto load all svg files in [libs/icons](libs/icons/). Please make sure new icon is optimized using [svgomg](https://jakearchibald.github.io/svgomg/).
### Deploy to Now Cloud
### Deploy to Now
Badgen generate badges on the fly, which means it's stateless (not rely on any db service). Deploy your own Badgen Service to [Now Cloud](https://zeit.co/now) with one single command:
Badgen generate badges on the fly, which means it's stateless (not rely on any db service). Deploy your own Badgen Service to [Now][now-href] with one single command:
```
now amio/badgen-service -e GH_TOKEN=''
```
@ -57,12 +57,14 @@ now amio/badgen-service -e GH_TOKEN=''
Made with ❤️ by [Amio](https://github.com/amio),
built with ⚡️ from [badgen](https://github.com/amio/badgen).
[now-href]: https://zeit.co/now
[standard-src]: https://badgen.net/badge/code%20style/standard/F2A
[standard-href]: https://standardjs.com/
[dep-src]: https://badgen.net/david/dep/amio/badgen-service?label=deps
[dep-href]: https://david-dm.org/amio/badgen-service
[uptime-src]: https://badgen.net/uptime-robot/day/m780731617-a9e038618dc1aee36a44c4af
[response-src]: https://badgen.net/uptime-robot/response/m780731617-a9e038618dc1aee36a44c4af
[uptime-href]: https://stats.uptimerobot.com/z6nqBfYGB
[deploy-to-now]: https://badgen.net/badge/▲/$%20now%20amio%2Fbadgen-service/222
[response-src]: https://badgen.net/uptime-robot/response/m780731617-a9e038618dc1aee36a44c4af
[dependencies-src]: https://badgen.net/david/dep/amio/badgen-service?label=deps
[dependencies-href]: https://david-dm.org/amio/badgen-service/
[license-src]: https://badgen.net/github/license/amio/badgen-service
[license-href]: LICENSE.md
[standard-src]: https://badgen.net/badge/code%20style/standard/pink
[standard-href]: https://standardjs.com/
[deploy-to-now-src]: https://badgen.net/badge/▲/$%20now%20amio%2Fbadgen-service/222
[now-href]: https://zeit.co/now/

Wyświetl plik

@ -1,6 +1,12 @@
# api.badgen.net
Serve badge data as json.
- Same url path as badgen.net
- Mainly for live badges
## Examples
- https://api.badgen.net/npm/v/micro
- https://api.badgen.net/npm/dependents/got
- https://api.badgen.net/github/dependents-pkg/chalk/chalk

Wyświetl plik

@ -1,6 +1,7 @@
# Badgen
Fast badge generating service.
[![classic](https://badgen.net/badge/style/classic/pink)](https://badgen.net)
[![flat](https://flat.badgen.net/badge/style/flat/pink)](https://flat.badgen.net)
@ -29,24 +30,24 @@ Available color names:
Available icons:
![](/badge//travis?icon=travis)
![](/badge//circleci?icon=circleci)
![](/badge//airbnb?icon=airbnb)
![](/badge//apple?icon=apple)
![](/badge//appveyor?icon=appveyor)
![](/badge//dependabot?icon=dependabot)
![](/badge//atom?icon=atom)
![](/badge//chrome?icon=chrome)
![](/badge//circleci?icon=circleci)
![](/badge//codecov?icon=codecov)
![](/badge//dependabot?icon=dependabot)
![](/badge//docker?icon=docker)
![](/badge//firefox?icon=firefox)
![](/badge//github?icon=github)
![](/badge//gitlab?icon=gitlab)
![](/badge//slack?icon=slack)
![](/badge//gitter?icon=gitter)
![](/badge//firefox?icon=firefox)
![](/badge//chrome?icon=chrome)
![](/badge//twitter?icon=twitter)
![](/badge//terminal?icon=terminal)
![](/badge//patreon?icon=patreon)
![](/badge//airbnb?icon=airbnb)
![](/badge//atom?icon=atom)
![](/badge//apple?icon=apple)
![](/badge//slack?icon=slack)
![](/badge//terminal?icon=terminal)
![](/badge//travis?icon=travis)
![](/badge//twitter?icon=twitter)
![](/badge//windows?icon=windows)
Available query params:
@ -64,7 +65,7 @@ Available query params:
| Preview | URL |
| ------- | --- |
|![](/badge/Swift/4.2/orange) | [/badge/Swift/4.0/orange](/badge/Swift/4.2/orange)
|![](/badge/Swift/4.2/orange) | [/badge/Swift/4.2/orange](/badge/Swift/4.2/orange)
|![](/badge/license/MIT/blue) | [/badge/license/MIT/blue](/badge/license/MIT/blue)
|![](/badge/chat/on%20gitter/cyan) | [/badge/chat/on%20gitter/cyan](/badge/chat/on%20gitter/cyan)
|![](/badge/stars/★★★★☆/green) | [/badge/stars/★★★★☆](/badge/stars/★★★★☆/green)
@ -82,11 +83,15 @@ Available query params:
['latest release', '/github/release/babel/babel'],
['latest stable release', '/github/release/babel/babel/stable'],
['latest tag', '/github/tag/micromatch/micromatch'],
['watchers', '/github/watchers/micromatch/micromatch'],
['stars', '/github/stars/micromatch/micromatch'],
['forks', '/github/forks/micromatch/micromatch'],
['watchers', '/github/watchers/micromatch/micromatch'],
['issues', '/github/issues/micromatch/micromatch'],
['open issues', '/github/open-issues/micromatch/micromatch']
['open issues', '/github/open-issues/micromatch/micromatch'],
['closed issues', '/github/closed-issues/micromatch/micromatch'],
['license', '/github/license/micromatch/micromatch'],
['repository dependents', '/github/dependents-repo/micromatch/micromatch'],
['package dependents', '/github/dependents-pkg/micromatch/micromatch']
],
/* release registries */
npm: [

Wyświetl plik

@ -1,5 +1,6 @@
const millify = require('millify')
const axios = require('../axios.js')
const semColor = require('../utils/sem-color.js')
// https://atom.io/api/packages/*
@ -33,7 +34,7 @@ async function pkg (topic, args) {
return {
subject: `apm`,
status: `v${meta.releases.latest}` || 'unknown',
color: 'green'
color: semColor(meta.releases.latest)
}
}
case 'license': {

Wyświetl plik

@ -37,7 +37,7 @@ async function coverage (vscType, user, repo, branch) {
return {
subject: 'coverage',
status: Number(data.commit.totals.c).toFixed(1) + '%',
status: Number(Number(data.commit.totals.c).toFixed(1)) + '%',
color: covColor(data.commit.totals.c)
}
}

Wyświetl plik

@ -12,7 +12,7 @@ module.exports = async function (topic, platform, user, repo, branch) {
return {
subject: 'coverage',
status: Number(covered_percent).toFixed(1) + '%',
status: Number(covered_percent.toFixed(1)) + '%',
color: covColor(covered_percent)
}
}

Wyświetl plik

@ -10,16 +10,14 @@ module.exports = async function (topic, ...args) {
return release(...args)
case 'tag':
return tag(...args)
case 'stars':
return stats('stargazers', ...args)
case 'forks':
return stats('forks', ...args)
case 'watchers':
return stats('watchers', ...args)
case 'open-issues':
return issues('open', ...args)
case 'stars':
case 'forks':
case 'issues':
return issues('all', ...args)
case 'open-issues':
case 'closed-issues':
case 'license':
return stats(topic, ...args)
case 'dependents-repo':
return dependents('REPOSITORY', ...args)
case 'dependents-pkg':
@ -77,6 +75,103 @@ async function tag (user, repo) {
}
}
function queryGithub (query) {
return axios.post('https://api.github.com/graphql', { query }, {
headers: {
'Accept': 'application/vnd.github.hawkgirl-preview+json',
'Authorization': `bearer ${token}`
}
}).then(res => res.data)
}
async function stats (topic, user, repo) {
let query = ''
switch (topic) {
case 'watchers':
query = `watchers { totalCount }`
break
case 'stars':
query = `stargazers { totalCount }`
break
case 'forks':
query = `forks { totalCount }`
break
case 'issues':
query = `issues { totalCount }`
break
case 'open-issues':
query = `issues(states:[OPEN]) { totalCount }`
break
case 'closed-issues':
query = `issues(states:[CLOSED]) { totalCount }`
break
case 'license':
query = `licenseInfo { spdxId }`
break
}
const { data, errors } = await queryGithub(`
query {
repository(owner:"${user}", name:"${repo}") {
${query}
}
}
`)
if (errors) {
console.error(JSON.stringify(errors))
return { subject: topic }
}
switch (topic) {
case 'watchers':
case 'forks':
case 'issues':
return {
subject: topic,
status: data.repository[topic].totalCount,
color: 'blue'
}
case 'stars':
return {
subject: topic,
status: data.repository.stargazers.totalCount,
color: 'blue'
}
case 'open-issues':
return {
subject: 'open issues',
status: data.repository.issues.totalCount,
color: 'orange'
}
case 'closed-issues':
return {
subject: 'closed issues',
status: data.repository.issues.totalCount,
color: 'blue'
}
case 'license':
return {
subject: topic,
status: data.repository.licenseInfo.spdxId,
color: 'blue'
}
default:
return {
subject: 'github',
status: 'unknown topic',
color: 'grey'
}
}
}
function parseDependents (html, type) {
const $ = cheerio.load(html)
const depLink = $(`a[href$="?dependent_type=${type}"]`)
if (depLink.length !== 1) return -1
return depLink.text().replace(/[^0-9,]/g, '')
}
async function dependents (type, user, repo) {
const html = await axios({
url: `https://github.com/${user}/${repo}/network/dependents`,
@ -91,72 +186,3 @@ async function dependents (type, user, repo) {
color: 'blue'
}
}
function parseDependents (html, type) {
const $ = cheerio.load(html)
const depLink = $(`a[href$="?dependent_type=${type}"]`)
if (depLink.length !== 1) return -1
return depLink.text().replace(/[^0-9,]/g, '')
}
function queryGithub (query) {
return axios.post('https://api.github.com/graphql', { query }, {
headers: {
'Accept': 'application/vnd.github.hawkgirl-preview+json',
'Authorization': `bearer ${token}`
}
}).then(res => res.data)
}
async function issues (filter, user, repo) {
const queryFilter = filter === 'open' ? '(states:[OPEN])' : ''
const { data, errors } = await queryGithub(`
query {
repository(owner:"${user}", name:"${repo}") {
issues${queryFilter} {
totalCount
}
}
}
`)
if (errors) {
console.error(JSON.stringify(errors))
return { subject: 'issues' }
} else {
return {
subject: filter === 'open' ? 'open issues' : 'issues',
status: data.repository.issues.totalCount,
color: filter === 'open' ? 'orange' : 'blue'
}
}
}
async function stats (topic, user, repo) {
const { data, errors } = await queryGithub(`
query {
repository(owner:"${user}", name:"${repo}") {
forks {
totalCount
}
stargazers {
totalCount
}
watchers {
totalCount
}
}
}
`)
if (errors) {
console.error(JSON.stringify(errors))
return { subject: topic }
} else {
return {
subject: topic.replace('stargazers', 'stars'),
status: data.repository[topic].totalCount,
color: 'blue'
}
}
}

Wyświetl plik

@ -7,6 +7,7 @@ module.exports = serveMarked('libs/index.md', {
body { max-width: inherit }
body > * { width: 960px; margin-left: auto; margin-right: auto; box-sizing: border-box }
h1 + p { letter-spacing: 0.1px }
h1 + p + p { text-align: center }
h1 + p a { display: inline-block; margin-top: 1em; padding: 4px; height: 20px }
img { height: 20px }
@ -59,6 +60,7 @@ module.exports = serveMarked('libs/index.md', {
</p>
</segment>
<aside>
<a href="https://api.badgen.net">API</a>
<a href="https://github.com/amio/badgen-service">GitHub</a>
<a href="https://twitter.com/badgen_net">Twitter</a>
</aside>