Skip to content

Commit 6790017

Browse files
committed
⚡ Update calls to use Github OAuth tokens
1 parent 5a3dee6 commit 6790017

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎lib/router.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const yaml = require('js-yaml')
44

55
const schema = require('./schema')
66

7+
const GITHUB_CREDENTIALS = (process.env.CLIENT_ID && process.env.CLIENT_SECRET)
8+
? `client_id=${process.env.CLIENT_ID}&client_secret=${process.env.CLIENT_SECRET}`
9+
: ''
710
const getJSON = uri => requestPromise({
811
uri,
912
headers: { 'User-Agent': process.env.APP_ID || 'pull[bot]' },
@@ -56,11 +59,11 @@ module.exports = app => {
5659
case 'triggered':
5760
params = ('plain' in req.query) ? {
5861
subject: '',
59-
status: `${(await getJSON(`https://api.github.com/search/issues?q=author:app/pull&per_page=1`)).total_count}`,
62+
status: `${(await getJSON(`https://api.github.com/search/issues?q=author:app/pull&per_page=1&${GITHUB_CREDENTIALS}`)).total_count}`,
6063
color: 'blue'
6164
} : {
6265
subject: 'triggered',
63-
status: `${(await getJSON(`https://api.github.com/search/issues?q=author:app/pull&per_page=1`)).total_count} times`,
66+
status: `${(await getJSON(`https://api.github.com/search/issues?q=author:app/pull&per_page=1&${GITHUB_CREDENTIALS}`)).total_count} times`,
6467
color: 'blue'
6568
}
6669
break
@@ -115,14 +118,14 @@ module.exports = app => {
115118

116119
routes.get('/check/:owner/:repo', (req, res) => {
117120
app.log.info(`[${req.params.owner}/${req.params.repo}] Checking ${app.CONFIG_FILENAME}`)
118-
getJSON(`https://api.github.com/repos/${req.params.owner}/${req.params.repo}/contents/.github/${app.CONFIG_FILENAME}?client_id=${process.env.CLIENT_ID || ''}&client_secret=${process.env.CLIENT_SECRET || ''}`)
121+
getJSON(`https://api.github.com/repos/${req.params.owner}/${req.params.repo}/contents/.github/${app.CONFIG_FILENAME}?${GITHUB_CREDENTIALS}`)
119122
.then(json => Buffer.from(json.content, 'base64').toString())
120123
.then(yml => yaml.safeLoad(yml))
121124
.then((config) => {
122125
const { error, value } = schema.validate(config)
123126
if (error) throw error
124127
const reqs = value.rules.map(r => new Promise((resolve, reject) => {
125-
getJSON(`https://api.github.com/repos/${req.params.owner}/${req.params.repo}/compare/${r.base}...${r.upstream}?client_id=${process.env.CLIENT_ID || ''}&client_secret=${process.env.CLIENT_SECRET || ''}`)
128+
getJSON(`https://api.github.com/repos/${req.params.owner}/${req.params.repo}/compare/${r.base}...${r.upstream}?${GITHUB_CREDENTIALS}`)
126129
.then(githubRes => resolve())
127130
.catch(e => reject(e))
128131
}))

0 commit comments

Comments
 (0)