diff --git a/.all-contributorsrc b/.all-contributorsrc
index 1719b5f..fe13248 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -232,7 +232,7 @@
"avatar_url": "https://avatars2.githubusercontent.com/u/8073251?v=4",
"profile": "https://github.com/xuchaoying",
"contributions": [
- "code",
+ "code"
]
},
{
@@ -243,6 +243,17 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "jakebolam",
+ "name": "Jake Bolam",
+ "avatar_url": "https://avatars2.githubusercontent.com/u/3534236?v=4",
+ "profile": "https://jakebolam.com",
+ "contributions": [
+ "code",
+ "doc",
+ "test"
+ ]
}
]
}
diff --git a/README.md b/README.md
index 3fd5873..6e86d7a 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
[![version][version-badge]][package] [![downloads][downloads-badge]][downloads]
[![MIT License][license-badge]][license]
-[![All Contributors](https://img.shields.io/badge/all_contributors-24-orange.svg?style=flat-square)](#contributors)
+[![All Contributors](https://img.shields.io/badge/all_contributors-26-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc]
[![Watch on GitHub][github-watch-badge]][github-watch]
[![Star on GitHub][github-star-badge]][github-star]
@@ -140,7 +140,7 @@ Where `username` is the user's GitHub or Gitlab username, and `contribution` is
- tutorial: [✅](# 'Tutorials')
- video: [📹](# 'Videos')
-Please note that if you are using a self-hosted gitlab instance, before adding
+Please note that if you are using a self-hosted gitlab instance, before adding
contributor, you need to set an environment variable named `PRIVATE_TOKEN` first.
> Private token is the personal access token to authenticate with the GitLab API.
@@ -163,7 +163,7 @@ all-contributors check
```
> Due to GitHub API restrictions, this command only works for projects with less
-> than 500 contributors.
+> than 500 contributors. (Unless you set a PRIVATE_TOKEN) as mentioned below
## Configuration
@@ -210,6 +210,10 @@ These are the keys you can specify:
}
```
+In some cases you may see the error message 'GitHub API rate limit exceeded for xxx'. You may need to set an environment variable named `PRIVATE_TOKEN` in order to circumvent this [GitHub rate limit](https://developer.github.com/v3/rate_limit/).
+
+> Private token is your personal access token to authenticate with the GitHub API.
+
## Contributors
Thanks goes to these wonderful people
@@ -221,9 +225,8 @@ Thanks goes to these wonderful people
| :---: | :---: | :---: | :---: | :---: | :---: |
| [
Jerod Santo](https://jerodsanto.net)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jerodsanto "Code") | [
Kevin Jalbert](https://github.com/kevinjalbert)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=kevinjalbert "Code") | [
tunnckoCore](https://i.am.charlike.online)
[🔧](#tool-charlike "Tools") | [
Mehdi Achour](https://machour.idk.tn/)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=machour "Code") | [
Roy Revelt](https://codsen.com)
[🐛](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3Arevelt "Bug reports") | [
Chris Vickery](https://github.com/chrisinajar)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=chrisinajar "Code") |
| [
Bryce Reynolds](https://github.com/brycereynolds)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=brycereynolds "Code") | [
James, please](http://www.jmeas.com)
[🤔](#ideas-jmeas "Ideas, Planning, & Feedback") [💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jmeas "Code") | [
Spyros Ioakeimidis](http://www.spyros.io)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=spirosikmd "Code") | [
Fernando Costa](https://github.com/fadc80)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=fadc80 "Code") | [
snipe](https://snipe.net)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=snipe "Documentation") | [
Gant Laborde](http://gantlaborde.com/)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=GantMan "Code") |
-| [
Md Zubair Ahmed](https://in.linkedin.com/in/mzubairahmed)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Documentation") [🐛](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3AM-ZubairAhmed "Bug reports") [💻](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Code") [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Tests") | [
Divjot Singh](http://bogas04.github.io)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [
João Marques](https://github.com/tigermarques)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Documentation") [🤔](#ideas-tigermarques "Ideas, Planning, & Feedback") | [
Andrew Lisowski](http://hipstersmoothie.com)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=hipstersmoothie "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=hipstersmoothie "Documentation") [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=hipstersmoothie "Tests") | [
Xianming Zhong](https://github.com/chinesedfan)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chinesedfan "Documentation") | [
Dura](https://github.com/chris-dura)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chris-dura "Documentation") | | [
C.Y.Xu](https://github.com/xuchaoying)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Documentation") |
-| [
C.Y.Xu](https://github.com/xuchaoying)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Documentation") |
-
+| [
Md Zubair Ahmed](https://in.linkedin.com/in/mzubairahmed)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Documentation") [🐛](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3AM-ZubairAhmed "Bug reports") [💻](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Code") [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=M-ZubairAhmed "Tests") | [
Divjot Singh](http://bogas04.github.io)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [
João Marques](https://github.com/tigermarques)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=tigermarques "Documentation") [🤔](#ideas-tigermarques "Ideas, Planning, & Feedback") | [
Andrew Lisowski](http://hipstersmoothie.com)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=hipstersmoothie "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=hipstersmoothie "Documentation") [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=hipstersmoothie "Tests") | [
Xianming Zhong](https://github.com/chinesedfan)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chinesedfan "Documentation") | [
C.Y.Xu](https://github.com/xuchaoying)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Code") |
+| [
Dura](https://github.com/chris-dura)
[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chris-dura "Documentation") | [
Jake Bolam](https://jakebolam.com)
[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jakebolam "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=jakebolam "Documentation") [⚠️](https://github.com/jfmengels/all-contributors-cli/commits?author=jakebolam "Tests") |
This project follows the
diff --git a/src/repo/__tests__/github.js b/src/repo/__tests__/github.js
index bd93624..839c77a 100644
--- a/src/repo/__tests__/github.js
+++ b/src/repo/__tests__/github.js
@@ -89,6 +89,40 @@ test('fill in the name when null is returned', async () => {
expect(info.name).toBe('nodisplayname')
})
+test('attaches token when supplied', async () => {
+ const mockAuthToken = 'myMock-token-adaskjda'
+ nock('https://api.github.com')
+ .matchHeader('authorization', `token ${mockAuthToken}`)
+ .get('/users/test-token')
+ .reply(200, {
+ html_url: 'test-token',
+ })
+
+ await(getUserInfo('test-token', 'https://github.com', mockAuthToken))
+})
+
+test('attaches no token when supplied empty', async () => {
+ nock('https://api.github.com')
+ .matchHeader('authorization', '')
+ .get('/users/test-token')
+ .reply(200, {
+ html_url: 'test-token',
+ })
+
+ await(getUserInfo('test-token', 'https://github.com', ''))
+})
+
+test('attaches no token when not supplied', async () => {
+ nock('https://api.github.com')
+ .matchHeader('authorization', '')
+ .get('/users/test-token')
+ .reply(200, {
+ html_url: 'test-token',
+ })
+
+ await(getUserInfo('test-token'))
+})
+
test('fill in the name when an empty string is returned', async () => {
nock('https://api.github.com')
.get('/users/nodisplayname')
diff --git a/src/repo/github.js b/src/repo/github.js
index 0c49f7e..dd59b49 100644
--- a/src/repo/github.js
+++ b/src/repo/github.js
@@ -1,14 +1,13 @@
const pify = require('pify')
const request = pify(require('request'))
-function getRequestHeaders() {
+function getRequestHeaders(optionalPrivateToken = '') {
const requestHeaders = {
'User-Agent': 'request',
}
-
- const optionalAuthToken = process.env.GITHUB_TOKEN
- if (optionalAuthToken) {
- requestHeaders.Authorization = `token ${optionalAuthToken}`
+
+ if (optionalPrivateToken && optionalPrivateToken.length > 0) {
+ requestHeaders.Authorization = `token ${optionalPrivateToken}`
}
return requestHeaders
@@ -28,11 +27,11 @@ function getNextLink(link) {
return nextLink.split(';')[0].slice(1, -1)
}
-function getContributorsPage(url) {
+function getContributorsPage(url, optionalPrivateToken) {
return request
.get({
url,
- headers: getRequestHeaders(),
+ headers: getRequestHeaders(optionalPrivateToken),
})
.then(res => {
const body = JSON.parse(res.body)
@@ -55,7 +54,7 @@ function getContributorsPage(url) {
})
}
-const getUserInfo = function(username, hostname) {
+const getUserInfo = function(username, hostname, optionalPrivateToken) {
/* eslint-disable complexity */
if (!hostname) {
hostname = 'https://github.com'
@@ -65,7 +64,7 @@ const getUserInfo = function(username, hostname) {
return request
.get({
url: `${root}/users/${username}`,
- headers: getRequestHeaders(),
+ headers: getRequestHeaders(optionalPrivateToken),
})
.then(res => {
const body = JSON.parse(res.body)
@@ -87,14 +86,14 @@ const getUserInfo = function(username, hostname) {
})
}
-const getContributors = function(owner, name, hostname) {
+const getContributors = function(owner, name, hostname, optionalPrivateToken) {
if (!hostname) {
hostname = 'https://github.com'
}
const root = hostname.replace(/:\/\//, '://api.')
const url = `${root}/repos/${owner}/${name}/contributors?per_page=100`
- return getContributorsPage(url)
+ return getContributorsPage(url, optionalPrivateToken)
}
module.exports = {