Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #219 from ntsim/gitlab-support
Add GitLab support
- Loading branch information
Showing
40 changed files
with
11,372 additions
and
1,690 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
.idea/ | ||
*.iml | ||
|
||
config.json | ||
config.*.json | ||
!config.test.json | ||
!config.example.json | ||
node_modules/ | ||
staticman_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ cache: | |
notifications: | ||
email: false | ||
node_js: | ||
- '6' | ||
- '8.11.3' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM node:6.7.0 | ||
FROM node:8.11.3 | ||
|
||
# Create app directory | ||
RUN mkdir -p /app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
'use strict' | ||
|
||
const gitFactory = require('../lib/GitServiceFactory') | ||
const oauth = require('../lib/OAuth') | ||
const RSA = require('../lib/RSA') | ||
const Staticman = require('../lib/Staticman') | ||
|
||
module.exports = (req, res) => { | ||
const staticman = new Staticman(req.params) | ||
staticman.setConfigPath() | ||
|
||
let requestAccessToken | ||
|
||
switch (req.params.service) { | ||
case 'gitlab': | ||
requestAccessToken = siteConfig => | ||
oauth.requestGitLabAccessToken( | ||
req.query.code, | ||
siteConfig.get('gitlabAuth.clientId'), | ||
siteConfig.get('gitlabAuth.clientSecret'), | ||
siteConfig.get('gitlabAuth.redirectUri') | ||
) | ||
break | ||
default: | ||
requestAccessToken = siteConfig => | ||
oauth.requestGitHubAccessToken( | ||
req.query.code, | ||
siteConfig.get('githubAuth.clientId'), | ||
siteConfig.get('githubAuth.clientSecret'), | ||
siteConfig.get('githubAuth.redirectUri') | ||
) | ||
} | ||
|
||
return staticman.getSiteConfig() | ||
.then(requestAccessToken) | ||
.then((accessToken) => { | ||
const git = gitFactory.create(req.params.service, { | ||
oauthToken: accessToken | ||
}) | ||
|
||
// TODO: Simplify this when v2 support is dropped. | ||
const getUser = req.params.version === '2' && req.params.service === 'github' | ||
? git.api.users.get({}).then(({data}) => data) | ||
: git.getCurrentUser() | ||
|
||
return getUser | ||
.then((user) => { | ||
res.send({ | ||
accessToken: RSA.encrypt(accessToken), | ||
user | ||
}) | ||
}) | ||
}) | ||
.catch((err) => { | ||
console.log('ERR:', err) | ||
|
||
const statusCode = err.statusCode || 401 | ||
|
||
res.status(statusCode).send({ | ||
statusCode, | ||
message: err.message | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.