mirror of
https://github.com/all-contributors/cli.git
synced 2025-01-09 13:36:29 +00:00
feat: support Gitlab self hosted instance (#95)
* feat: support Gitlab self hosted instance (#89) * docs: fix some doc typo fixes: #89
This commit is contained in:
parent
533813b3db
commit
0d1346d04e
6 changed files with 99 additions and 14 deletions
|
@ -2,6 +2,7 @@
|
|||
"projectOwner": "jfmengels",
|
||||
"projectName": "all-contributors-cli",
|
||||
"imageSize": 100,
|
||||
"repoType": "github",
|
||||
"commit": false,
|
||||
"contributorsPerLine": 6,
|
||||
"contributors": [
|
||||
|
@ -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",
|
||||
|
@ -234,6 +244,5 @@
|
|||
"doc"
|
||||
]
|
||||
}
|
||||
],
|
||||
"repoType": "github"
|
||||
]
|
||||
}
|
||||
|
|
15
README.md
15
README.md
|
@ -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
|
||||
|
@ -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 -->
|
||||
|
||||
|
|
17
package.json
17
package.json
|
@ -5,7 +5,9 @@
|
|||
"bin": {
|
||||
"all-contributors": "dist/cli.js"
|
||||
},
|
||||
"files": ["dist"],
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
|
@ -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 <jfm.engels@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
|
@ -38,10 +43,14 @@
|
|||
"yargs": "^10.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"kcd-scripts": "^0.29.0",
|
||||
"kcd-scripts": "^0.30.0",
|
||||
"nock": "^9.1.0"
|
||||
},
|
||||
"eslintIgnore": ["node_modules", "coverage", "dist"],
|
||||
"eslintIgnore": [
|
||||
"node_modules",
|
||||
"coverage",
|
||||
"dist"
|
||||
],
|
||||
"eslintConfig": {
|
||||
"extends": "./node_modules/kcd-scripts/eslint.js",
|
||||
"rules": {
|
||||
|
|
|
@ -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', ''),
|
||||
)
|
||||
})
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
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'
|
||||
|
@ -9,7 +17,10 @@ const getUserInfo = function(username, hostname) {
|
|||
|
||||
return request
|
||||
.get({
|
||||
url: `${hostname}/api/v4/users?username=${username}`,
|
||||
url: addPrivateToken(
|
||||
`${hostname}/api/v4/users?username=${username}`,
|
||||
privateToken,
|
||||
),
|
||||
headers: {
|
||||
'User-Agent': 'request',
|
||||
},
|
||||
|
@ -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 {
|
||||
|
@ -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',
|
||||
},
|
||||
|
@ -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',
|
||||
},
|
||||
|
|
|
@ -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',
|
||||
|
@ -81,6 +82,7 @@ const getUserInfo = function(username, repoType, repoHost) {
|
|||
return SUPPORTED_REPO_TYPES[repoType].getUserInfo(
|
||||
username,
|
||||
getHostname(repoType, repoHost),
|
||||
privateToken,
|
||||
)
|
||||
}
|
||||
return null
|
||||
|
@ -92,6 +94,7 @@ const getContributors = function(owner, name, repoType, repoHost) {
|
|||
owner,
|
||||
name,
|
||||
getHostname(repoType, repoHost),
|
||||
privateToken,
|
||||
)
|
||||
}
|
||||
return null
|
||||
|
|
Loading…
Reference in a new issue