Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Gitlab self hosted instance (#89) #95

Merged
merged 3 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"projectOwner": "jfmengels",
"projectName": "all-contributors-cli",
"imageSize": 100,
"repoType": "github",
"commit": false,
"contributorsPerLine": 6,
"contributors": [
Expand Down Expand Up @@ -225,6 +226,15 @@
"doc"
]
},
{
"login": "xuchaoying",
"name": "C.Y.Xu",
"avatar_url": "https://avatars2.githubusercontent.com/u/8073251?v=4",
"profile": "https://github.com/xuchaoying",
"contributions": [
"code",
]
},
{
"login": "chris-dura",
"name": "Dura",
Expand All @@ -234,6 +244,5 @@
"doc"
]
}
],
"repoType": "github"
]
}
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ 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
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.

```console
# set private token on linux
export PRIVATE_TOKEN=your_private_token
# set private token on windows
set PRIVATE_TOKEN=your_private_token
```

### Check for missing contributors

Use `check` to compare contributors from GitHub with the ones credited in your
Expand Down Expand Up @@ -205,7 +217,8 @@ Thanks goes to these wonderful people
| :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars3.githubusercontent.com/u/8212?v=3" width="100px;"/><br /><sub><b>Jerod Santo</b></sub>](https://jerodsanto.net)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jerodsanto "Code") | [<img src="https://avatars1.githubusercontent.com/u/574871?v=3" width="100px;"/><br /><sub><b>Kevin Jalbert</b></sub>](https://github.com/kevinjalbert)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=kevinjalbert "Code") | [<img src="https://avatars3.githubusercontent.com/u/5038030?v=4" width="100px;"/><br /><sub><b>tunnckoCore</b></sub>](https://i.am.charlike.online)<br />[🔧](#tool-charlike "Tools") | [<img src="https://avatars2.githubusercontent.com/u/304450?v=4" width="100px;"/><br /><sub><b>Mehdi Achour</b></sub>](https://machour.idk.tn/)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=machour "Code") | [<img src="https://avatars1.githubusercontent.com/u/8344688?v=4" width="100px;"/><br /><sub><b>Roy Revelt</b></sub>](https://codsen.com)<br />[🐛](https://github.com/jfmengels/all-contributors-cli/issues?q=author%3Arevelt "Bug reports") | [<img src="https://avatars1.githubusercontent.com/u/422331?v=4" width="100px;"/><br /><sub><b>Chris Vickery</b></sub>](https://github.com/chrisinajar)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=chrisinajar "Code") |
| [<img src="https://avatars2.githubusercontent.com/u/1026002?v=4" width="100px;"/><br /><sub><b>Bryce Reynolds</b></sub>](https://github.com/brycereynolds)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=brycereynolds "Code") | [<img src="https://avatars3.githubusercontent.com/u/2322305?v=4" width="100px;"/><br /><sub><b>James, please</b></sub>](http://www.jmeas.com)<br />[🤔](#ideas-jmeas "Ideas, Planning, & Feedback") [💻](https://github.com/jfmengels/all-contributors-cli/commits?author=jmeas "Code") | [<img src="https://avatars3.githubusercontent.com/u/1057324?v=4" width="100px;"/><br /><sub><b>Spyros Ioakeimidis</b></sub>](http://www.spyros.io)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=spirosikmd "Code") | [<img src="https://avatars3.githubusercontent.com/u/12335761?v=4" width="100px;"/><br /><sub><b>Fernando Costa</b></sub>](https://github.com/fadc80)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=fadc80 "Code") | [<img src="https://avatars0.githubusercontent.com/u/197404?v=4" width="100px;"/><br /><sub><b>snipe</b></sub>](https://snipe.net)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=snipe "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/997157?v=4" width="100px;"/><br /><sub><b>Gant Laborde</b></sub>](http://gantlaborde.com/)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=GantMan "Code") |
| [<img src="https://avatars2.githubusercontent.com/u/17708702?v=4" width="100px;"/><br /><sub><b>Md Zubair Ahmed</b></sub>](https://in.linkedin.com/in/mzubairahmed)<br />[📖](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") | [<img src="https://avatars3.githubusercontent.com/u/6177621?v=4" width="100px;"/><br /><sub><b>Divjot Singh</b></sub>](http://bogas04.github.io)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/15315098?v=4" width="100px;"/><br /><sub><b>João Marques</b></sub>](https://github.com/tigermarques)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/1192452?v=4" width="100px;"/><br /><sub><b>Andrew Lisowski</b></sub>](http://hipstersmoothie.com)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/1736154?v=4" width="100px;"/><br /><sub><b>Xianming Zhong</b></sub>](https://github.com/chinesedfan)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chinesedfan "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/3680914?v=4" width="100px;"/><br /><sub><b>Dura</b></sub>](https://github.com/chris-dura)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chris-dura "Documentation") |
| [<img src="https://avatars2.githubusercontent.com/u/17708702?v=4" width="100px;"/><br /><sub><b>Md Zubair Ahmed</b></sub>](https://in.linkedin.com/in/mzubairahmed)<br />[📖](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") | [<img src="https://avatars3.githubusercontent.com/u/6177621?v=4" width="100px;"/><br /><sub><b>Divjot Singh</b></sub>](http://bogas04.github.io)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=bogas04 "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/15315098?v=4" width="100px;"/><br /><sub><b>João Marques</b></sub>](https://github.com/tigermarques)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/1192452?v=4" width="100px;"/><br /><sub><b>Andrew Lisowski</b></sub>](http://hipstersmoothie.com)<br />[💻](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") | [<img src="https://avatars3.githubusercontent.com/u/1736154?v=4" width="100px;"/><br /><sub><b>Xianming Zhong</b></sub>](https://github.com/chinesedfan)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chinesedfan "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/3680914?v=4" width="100px;"/><br /><sub><b>Dura</b></sub>](https://github.com/chris-dura)<br />[📖](https://github.com/jfmengels/all-contributors-cli/commits?author=chris-dura "Documentation") | | [<img src="https://avatars2.githubusercontent.com/u/8073251?v=4" width="100px;"/><br /><sub><b>C.Y.Xu</b></sub>](https://github.com/xuchaoying)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Documentation") |
| [<img src="https://avatars2.githubusercontent.com/u/8073251?v=4" width="100px;"/><br /><sub><b>C.Y.Xu</b></sub>](https://github.com/xuchaoying)<br />[💻](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Code") [📖](https://github.com/jfmengels/all-contributors-cli/commits?author=xuchaoying "Documentation") |

<!-- ALL-CONTRIBUTORS-LIST:END -->

Expand Down
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"bin": {
"all-contributors": "dist/cli.js"
},
"files": ["dist"],
"files": [
"dist"
],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know whether maintainers care these format changes or not. But without them, it is easy to review and track history logs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these changes are generated by prettier automatically on commit (?), and prettier hadn't been run in awhile. So, these whitespace changes are probably the correct format.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chris-dura yes, maybe it's prettier. I didn't change the format at all.

"engines": {
"node": ">=4"
},
Expand All @@ -21,7 +23,10 @@
"type": "git",
"url": "https://github.com/jfmengels/all-contributors-cli.git"
},
"keywords": ["all-contributors", "contributors"],
"keywords": [
"all-contributors",
"contributors"
],
"author": "Jeroen Engels <[email protected]>",
"license": "MIT",
"bugs": {
Expand All @@ -38,10 +43,14 @@
"yargs": "^10.0.3"
},
"devDependencies": {
"kcd-scripts": "^0.29.0",
"kcd-scripts": "^0.30.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It solves #105. Good job!

"nock": "^9.1.0"
},
"eslintIgnore": ["node_modules", "coverage", "dist"],
"eslintIgnore": [
"node_modules",
"coverage",
"dist"
],
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js",
"rules": {
Expand Down
31 changes: 31 additions & 0 deletions src/repo/__tests__/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,34 @@ test('retrieve user from a different gitlab registry', async () => {
)
expect(info.name).toBe('No Display Name')
})

test('retrieve user from a gitlab registry that needs a token', async () => {
nock('http://gitlab.needtoken.com:3000')
.get('/api/v4/users?username=nodisplayname&private_token=faketoken')
.reply(200, [
{
username: 'nodisplayname',
name: 'No Display Name',
avatar_url:
'http://www.gravatar.com/avatar/3186450a99d1641bf75a44baa23f0826?s=80\u0026d=identicon',
web_url: 'https://gitlab.com/nodisplayname',
},
])

const info = await getUserInfo(
'nodisplayname',
'http://gitlab.needtoken.com:3000',
'faketoken',
)
expect(info.name).toBe('No Display Name')
})

test('handle error when no token is offered', async () => {
nock('http://gitlab.needtoken.com:3000')
.get('/api/v4/users?username=nodisplayname')
.reply(200, [])

await rejects(
getUserInfo('nodisplayname', 'http://gitlab.needtoken.com:3000', ''),
)
})
34 changes: 27 additions & 7 deletions src/repo/gitlab.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
const pify = require('pify')
const request = pify(require('request'))

const getUserInfo = function(username, hostname) {
const addPrivateToken = (url, privateToken = '') => {
if (privateToken === '') return url

return `${url}&private_token=${privateToken}`
.replace(/\?/g, '&')
.replace('&', '?')
}

const getUserInfo = function(username, hostname, privateToken) {
/* eslint-disable complexity */
if (!hostname) {
hostname = 'https://gitlab.com'
}

return request
.get({
url: `${hostname}/api/v4/users?username=${username}`,
url: addPrivateToken(
`${hostname}/api/v4/users?username=${username}`,
privateToken,
),
headers: {
'User-Agent': 'request',
},
Expand All @@ -22,6 +33,11 @@ const getUserInfo = function(username, hostname) {
throw new Error(`User ${username} not found`)
}

// no private token present
if (body.message) {
throw new Error(body.message)
}

const user = body[0]

return {
Expand All @@ -35,14 +51,17 @@ const getUserInfo = function(username, hostname) {
})
}

const getContributors = function(owner, name, hostname) {
const getContributors = function(owner, name, hostname, privateToken) {
if (!hostname) {
hostname = 'https://gitlab.com'
}

return request
.get({
url: `${hostname}/api/v4/projects?search=${name}`,
url: addPrivateToken(
`${hostname}/api/v4/projects?search=${name}`,
privateToken,
),
headers: {
'User-Agent': 'request',
},
Expand All @@ -69,9 +88,10 @@ const getContributors = function(owner, name, hostname) {

return request
.get({
url: `${hostname}/api/v4/projects/${
project.id
}/repository/contributors`,
url: addPrivateToken(
`${hostname}/api/v4/projects/${project.id}/repository/contributors`,
privateToken,
),
headers: {
'User-Agent': 'request',
},
Expand Down
3 changes: 3 additions & 0 deletions src/repo/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const githubAPI = require('./github')
const gitlabAPI = require('./gitlab')

const privateToken = (process.env && process.env.PRIVATE_TOKEN) || ''
const SUPPORTED_REPO_TYPES = {
github: {
value: 'github',
Expand Down Expand Up @@ -81,6 +82,7 @@ const getUserInfo = function(username, repoType, repoHost) {
return SUPPORTED_REPO_TYPES[repoType].getUserInfo(
username,
getHostname(repoType, repoHost),
privateToken,
)
}
return null
Expand All @@ -92,6 +94,7 @@ const getContributors = function(owner, name, repoType, repoHost) {
owner,
name,
getHostname(repoType, repoHost),
privateToken,
)
}
return null
Expand Down