Skip to content

Commit f2ba3c1

Browse files
committed
📝 Add /installations endpoint
1 parent 6eebde5 commit f2ba3c1

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
[![TravisCI](https://travis-ci.com/wei/pull.svg?branch=master)](https://travis-ci.com/wei/pull)
66
[![Codecov](https://img.shields.io/codecov/c/github/wei/pull/master.svg?maxAge=3600)](https://codecov.io/gh/wei/pull)
77
[![Depfu](https://img.shields.io/depfu/wei/pull.svg?maxAge=3600)](https://depfu.com/github/wei/pull)
8-
[![Installations](https://img.shields.io/badge/dynamic/json.svg?label=installed&url=https%3A%2F%2Fpull.now.sh%2Fprobot%2Fstats&query=%24.installations&colorB=007ec6&suffix=%20times&maxAge=3600)](https://probot.github.io/apps/pull/)
9-
[![Triggered #](https://img.shields.io/badge/dynamic/json.svg?label=triggered&url=https%3A%2F%2Fapi.github.com%2Fsearch%2Fissues%3Fq%3Dauthor%3Aapp%2Fpull%26per_page%3D1&query=%24.total_count&colorB=007ec6&suffix=%20times&maxAge=600)](https://github.com/issues?q=author%3Aapp%2Fpull)
8+
[![Installations](https://img.shields.io/badge/dynamic/json.svg?label=installed&url=https%3A%2F%2Fpull.now.sh%2Fprobot%2Fstats&query=%24.installations&colorB=007ec6&suffix=%20times&maxAge=600)](https://probot.github.io/apps/pull/)
9+
[![Managing](https://img.shields.io/badge/dynamic/json.svg?label=managing&url=https%3A%2F%2Fpull.now.sh%2Finstallations&query=%24.repos&colorB=007ec6&suffix=%20repos&maxAge=600)](https://probot.github.io/apps/pull/)
10+
[![Triggered #](https://img.shields.io/badge/dynamic/json.svg?label=triggered&url=https%3A%2F%2Fapi.github.com%2Fsearch%2Fissues%3Fq%3Dauthor%3Aapp%2Fpull%26per_page%3D1&query=%24.total_count&colorB=007ec6&suffix=%20times)](https://github.com/issues?q=author%3Aapp%2Fpull)
1011
<br/>
1112
[![Probot](https://img.shields.io/badge/built%20with-probot-orange.svg?maxAge=86400)](https://probot.github.io/)
1213
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg?maxAge=86400)](https://standardjs.com)

‎index.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const bsyslog = require('bunyan-syslog-udp')
99
const Pull = require('./lib/pull')
1010
const schema = require('./lib/schema')
1111

12+
const managedAccounts = []
13+
const managedRepos = []
14+
1215
module.exports = async (app) => {
1316
const papertrailHost = process.env.PAPERTRAIL_HOST
1417
const papertrailPort = parseInt(process.env.PAPERTRAIL_PORT, 10)
@@ -65,6 +68,13 @@ module.exports = async (app) => {
6568
}
6669

6770
async function forRepository (context) {
71+
if (managedAccounts.indexOf(context.payload.repository.owner.name) === -1) {
72+
managedAccounts.push(context.payload.repository.owner.name)
73+
}
74+
if (managedRepos.indexOf(context.payload.repository.full_name) === -1) {
75+
managedRepos.push(context.payload.repository.full_name)
76+
}
77+
6878
if (!context.payload.repository.fork) {
6979
app.log.info(`[${context.payload.repository.full_name}] Not a fork, unscheduled`)
7080
scheduler.stop(context.payload.repository)
@@ -115,6 +125,13 @@ module.exports = async (app) => {
115125

116126
routes.get('/', (req, res) => res.redirect('https://github.com/wei/pull#readme'))
117127

128+
routes.get('/installations', async (req, res) => {
129+
res.json({
130+
installations: managedAccounts.length,
131+
repos: managedRepos.length
132+
})
133+
})
134+
118135
routes.get('/check/:owner/:repo', (req, res) => {
119136
app.log.info(`[${req.params.owner}/${req.params.repo}] Checking ${PULL_CONFIG}`)
120137
fetch(`https://api.github.com/repos/${req.params.owner}/${req.params.repo}/contents/.github/${PULL_CONFIG}`)

0 commit comments

Comments
 (0)