|
1 | | -const { badgen } = require('badgen') |
2 | 1 | const requestPromise = require('request-promise') |
3 | 2 | const yaml = require('js-yaml') |
4 | 3 | const { clearConfig } = require('./get-config') |
@@ -39,94 +38,15 @@ module.exports = app => { |
39 | 38 | res.json(app.limiter.counts()) |
40 | 39 | }) |
41 | 40 |
|
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) |
113 | 45 | }) |
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() |
127 | 49 | }) |
128 | | - res.end(buf) |
129 | | - } |
130 | 50 | }) |
131 | 51 |
|
132 | 52 | routes.get('/process/:owner/:repo', (req, res) => { |
|
0 commit comments