Skip to content
This repository has been archived by the owner on Jun 6, 2022. It is now read-only.

Commit

Permalink
add alert for github API reach limit control
Browse files Browse the repository at this point in the history
  • Loading branch information
antiwinter committed Sep 16, 2019
1 parent 50264e5 commit 06a664e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions source/github.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Octokit = require('@octokit/rest')
const ok = new Octokit({
// auth: process.env.GITHUB_TOKEN
auth: process.env.GITHUB_TOKEN
})
const log = console.log

Expand Down Expand Up @@ -31,7 +31,7 @@ let api = {
? ok.repos.getBranch({ owner, repo, branch: ad.branch })
: ok.repos.listTags({ owner, repo })
h.then(err => {
log('got dat', JSON.stringify(err, null, 2))
// log('got dat', JSON.stringify(err, null, 2))
let data = err.data
let d = {
name: repo,
Expand Down Expand Up @@ -76,7 +76,17 @@ let api = {
done(d)
})
}).catch(err => {
log('err happened', err)
if (err) {
let msg = err.toString()
if (typeof msg === 'string' && msg.match(/rate limit/)) {
log(
'\nThe [github] API has reached its rate limits. You can either create a GITHUB_TOKEN env, or try another time after an hour.'
)
log(
'To aquire a GITHUB_TOKEN, goto https://github.com/settings/tokens, and click "Generate new token"\n'
)
}
}
done()
})
}
Expand Down

0 comments on commit 06a664e

Please sign in to comment.