Skip to content

Commit 99cdffa

Browse files
committed
🔥 Outsource badge generation
Fetching stats daily using GitHub Actions and host from pull-app/stats
1 parent c8d65df commit 99cdffa

4 files changed

Lines changed: 20 additions & 102 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
</a>
55
</p>
66
<p align="center">
7+
<a href="https://github.com/wei/pull">
8+
<img alt="GitHub Stars" src="https://badgen.net/github/stars/wei/pull?icon=github&cache=600" />
9+
</a>
710
<a href="https://github.com/apps/pull">
8-
<img alt="Managing" src="https://pull.git.ci/badge/managing" />
11+
<img alt="Managing" src="https://badgen.net/https/raw.githack.com/pull-app/stats/master/badges/managing.json?cache=600" />
912
</a>
1013
<a href="https://github.com/apps/pull">
11-
<img alt="Installations" src="https://pull.git.ci/badge/installed" />
14+
<img alt="Installations" src="https://badgen.net/https/raw.githack.com/pull-app/stats/master/badges/installed.json?cache=600" />
1215
</a>
1316
<a href="https://github.com/issues?q=author%3Aapp%2Fpull">
1417
<img alt="Triggered #" src="https://badgen.net/runkit/pull-triggered-badge-5e55hqhkhmid?cache=600" />
@@ -36,17 +39,18 @@
3639

3740
## Introduction
3841

39-
[![TravisCI](https://travis-ci.com/wei/pull.svg?branch=master)](https://travis-ci.com/wei/pull)
40-
[![Codecov](https://codecov.io/gh/wei/pull/branch/master/graph/badge.svg)](https://codecov.io/gh/wei/pull)
41-
[![Dependabot Status](https://api.dependabot.com/badges/status?host=github&repo=wei/pull)](https://dependabot.com)
42-
[![Probot](https://pull.git.ci/badge/built_with)](https://probot.github.io/)
43-
[![JavaScript Style Guide](https://pull.git.ci/badge/code_style)](https://standardjs.com)
42+
[![GitHub Status](https://badgen.net/github/status/wei/pull?icon=github)](https://github.com/wei/pull)
43+
[![TravisCI](https://badgen.net/travis/wei/pull?icon=travis&label=build)](https://travis-ci.com/wei/pull)
44+
[![Codecov](https://badgen.net/codecov/c/github/wei/pull?icon=codecov)](https://codecov.io/gh/wei/pull)
45+
[![Dependabot Status](https://badgen.net/badge/dependabot/enabled/green?icon=dependabot&cache=86400)](https://dependabot.com)
46+
[![Probot](https://badgen.net/badge/built%20with/probot/orange?icon=dependabot&cache=86400)](https://probot.github.io/)
47+
[![JavaScript Style Guide](https://badgen.net/badge/code%20style/standard/f2a?cache=86400)](https://standardjs.com)
4448
[![jest](https://facebook.github.io/jest/img/jest-badge.svg)](https://github.com/facebook/jest)
45-
[![MIT License](https://pull.git.ci/badge/license)](https://wei.mit-license.org)
49+
[![MIT License](https://badgen.net/badge/license/MIT/blue?cache=86400)](https://wei.mit-license.org)
4650

4751
> 🤖 a GitHub App built with [probot](https://github.com/probot/probot) that keeps your forks up-to-date with upstream via automated pull requests.
4852
49-
Trusted by [![Repository Count](https://pull.git.ci/badge/managing?plain&style=flat)](https://probot.github.io/apps/pull/) repositories, triggered [![Triggered #](https://badgen.net/runkit/pull-triggered-badge-5e55hqhkhmid?style=flat&label=&cache=600)](https://github.com/issues?q=author%3Aapp%2Fpull).
53+
Trusted by [![Repository Count](https://badgen.net/https/raw.githack.com/pull-app/stats/master/badges/managing.plain.json?style=flat&cache=600)](https://probot.github.io/apps/pull/) repositories, triggered [![Triggered #](https://badgen.net/runkit/pull-triggered-badge-5e55hqhkhmid?style=flat&label=&cache=600)](https://github.com/issues?q=author%3Aapp%2Fpull).
5054

5155
Want to support this open source service? [Please star it : )](https://github.com/wei/pull)
5256

‎lib/router.js‎

Lines changed: 7 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const { badgen } = require('badgen')
21
const requestPromise = require('request-promise')
32
const yaml = require('js-yaml')
43
const { clearConfig } = require('./get-config')
@@ -39,94 +38,15 @@ module.exports = app => {
3938
res.json(app.limiter.counts())
4039
})
4140

42-
routes.get('/badge/:type', async (req, res) => {
43-
let params
44-
try {
45-
switch (req.params.type) {
46-
case 'installed': {
47-
const installCount = Object.keys(app.scheduler.INSTALLATIONS).length
48-
params = ('plain' in req.query) ? {
49-
subject: '',
50-
status: `${installCount}`,
51-
color: 'blue'
52-
} : {
53-
subject: 'installed',
54-
status: `${installCount} times`,
55-
color: 'blue'
56-
}
57-
break
58-
}
59-
case 'managing': {
60-
const repoCount = Object.keys(app.scheduler.REPOSITORIES).length
61-
params = ('plain' in req.query) ? {
62-
subject: '',
63-
status: `${repoCount}`,
64-
color: 'blue'
65-
} : {
66-
subject: 'managing',
67-
status: `${repoCount} repos`,
68-
color: 'blue'
69-
}
70-
break
71-
}
72-
case 'triggered':
73-
params = ('plain' in req.query) ? {
74-
subject: '',
75-
status: `${(await getJSON(`https://api.github.com/search/issues?q=author:app/pull&per_page=1&${GITHUB_CREDENTIALS}`)).total_count}`,
76-
color: 'blue'
77-
} : {
78-
subject: 'triggered',
79-
status: `${(await getJSON(`https://api.github.com/search/issues?q=author:app/pull&per_page=1&${GITHUB_CREDENTIALS}`)).total_count} times`,
80-
color: 'blue'
81-
}
82-
break
83-
case 'code_style':
84-
params = {
85-
subject: 'code style',
86-
status: 'standard',
87-
color: 'green',
88-
maxAge: 86400
89-
}
90-
break
91-
case 'built_with':
92-
params = {
93-
subject: 'built with',
94-
status: 'probot',
95-
color: 'orange',
96-
maxAge: 86400
97-
}
98-
break
99-
case 'license':
100-
params = {
101-
subject: 'license',
102-
status: 'MIT',
103-
color: 'blue',
104-
maxAge: 86400
105-
}
106-
break
107-
default:
108-
throw Error('Invalid type')
109-
}
110-
111-
['subject', 'status', 'color', 'style', 'maxAge'].forEach(k => {
112-
if (k in req.query) params[k] = req.query[k]
41+
routes.get('/probot/stats', (req, res) => {
42+
getJSON('https://raw.githack.com/pull-app/stats/master/stats.json')
43+
.then(json => {
44+
res.json(json)
11345
})
114-
115-
const svgString = badgen(params).replace(/>\s+</g, '><')
116-
117-
res.writeHead(200, {
118-
'Content-Type': 'image/svg+xml;charset=utf-8',
119-
'Cache-Control': `max-age=${!Number.isNaN(params.maxAge) ? params.maxAge : 600}`
120-
})
121-
res.end(svgString)
122-
} catch (_) {
123-
const buf = Buffer.from('4749463839610100010000000021F90401000000002C00000000010001000002', 'hex')
124-
res.writeHead(200, {
125-
'Content-Type': 'image/gif',
126-
'Content-Length': buf.length
46+
.catch(e => {
47+
app.log.error(e, 'Failed to fetch stats.json')
48+
res.status(404).end()
12749
})
128-
res.end(buf)
129-
}
13050
})
13151

13252
routes.get('/process/:owner/:repo', (req, res) => {

‎package-lock.json‎

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"test:watch": "jest --watchAll --notify --notifyMode=change --coverage"
1414
},
1515
"dependencies": {
16-
"badgen": "^3.2.1",
1716
"bottleneck": "^2.19.5",
1817
"bunyan-syslog-udp": "^0.2.0",
1918
"joi": "^14.3.1",

0 commit comments

Comments
 (0)