mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat: way to avoid github API limit (#122)
<!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar with and follow the Code of Conduct for this project (found in the CODE_OF_CONDUCT.md file). Also, please make sure you're familiar with and follow the instructions in the contributing guidelines (found in the CONTRIBUTING.md file). If you're new to contributing to open source projects, you might find this free video course helpful: http://kcd.im/pull-request Please fill out the information below to expedite the review and (hopefully) merge of your pull request! --> <!-- What changes are being made? (What feature/bug is being fixed here?) --> **What**: Add a way to avoid GITHUB API LIMIT by supplying an optional GITHUB_AUTH token to increase github rate limiting from 50 requests to 5000 (and limited by user, not IP) <!-- Why are these changes necessary? --> **Why**: To address: #121 <!-- How were these changes implemented? --> **How**: By Me <!-- Have you done all of these things? --> **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> - [ ] Documentation - [ ] Tests - [ ] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? --> - [ ] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> <!-- feel free to add additional comments -->
This commit is contained in:
parent
7a0ece7ee6
commit
e18363f081
1 changed files with 15 additions and 6 deletions
|
@ -1,6 +1,19 @@
|
|||
const pify = require('pify')
|
||||
const request = pify(require('request'))
|
||||
|
||||
function getRequestHeaders() {
|
||||
const requestHeaders = {
|
||||
'User-Agent': 'request',
|
||||
}
|
||||
|
||||
const optionalAuthToken = process.env.GITHUB_TOKEN
|
||||
if (optionalAuthToken) {
|
||||
requestHeaders.Authorization = `token ${optionalAuthToken}`
|
||||
}
|
||||
|
||||
return requestHeaders
|
||||
}
|
||||
|
||||
function getNextLink(link) {
|
||||
if (!link) {
|
||||
return null
|
||||
|
@ -19,9 +32,7 @@ function getContributorsPage(url) {
|
|||
return request
|
||||
.get({
|
||||
url,
|
||||
headers: {
|
||||
'User-Agent': 'request',
|
||||
},
|
||||
headers: getRequestHeaders(),
|
||||
})
|
||||
.then(res => {
|
||||
const body = JSON.parse(res.body)
|
||||
|
@ -54,9 +65,7 @@ const getUserInfo = function(username, hostname) {
|
|||
return request
|
||||
.get({
|
||||
url: `${root}/users/${username}`,
|
||||
headers: {
|
||||
'User-Agent': 'request',
|
||||
},
|
||||
headers: getRequestHeaders(),
|
||||
})
|
||||
.then(res => {
|
||||
const body = JSON.parse(res.body)
|
||||
|
|
Loading…
Reference in a new issue