Skip to content

Commit 066bb19

Browse files
AustinAustin
authored andcommitted
Add GitHub Enterprise Support
1 parent 964cb39 commit 066bb19

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

README.md

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ strider-github
44
A provider for strider that integrates with github to provide easy setup of
55
your projects. It registers webhooks and sets up ssh keys (if you so choose).
66

7-
[![NPM](https://nodei.co/npm/strider-github.png)](https://nodei.co/npm/strider-github/)
7+
[![NPM](https://nodei.co/npm/strider-github.png)](https://nodei.co/npm/strider-github/)
88
[![Build Status](https://travis-ci.org/Strider-CD/strider-github.svg)](https://travis-ci.org/Strider-CD/strider-github)
99

1010
Note: Supports using '[skip ci]' in your commit message to skip commits triggering a job.
@@ -13,24 +13,48 @@ Note: Supports using '[skip ci]' in your commit message to skip commits triggeri
1313

1414
If you are running on `localhost:3000` the default settings should work just fine.
1515

16-
### Use custom hostname and port
16+
### Environment Variables
1717

18-
To use a custom hostname and port:
18+
**`SERVER_NAME`** The url of your strider server. Defaults to `http://localhost:3000`.
1919

20-
- set this environment variables with you hosname/port information
20+
The following variables only need to be overridden if you are using github enterprise. See 'Enterprise Setup' below.
2121

22-
```
23-
PORT=9999
24-
SERVER_NAME="http://your.strider.hostname:9999"
25-
PLUGIN_GITHUB_APP_ID="hereComesTheId"
26-
PLUGIN_GITHUB_APP_SECRET="theSecretFromGithub"
27-
```
22+
**`PLUGIN_GITHUB_APP_ID`** Defaults to client ID of Strider-CD Github App
2823

29-
- register your own github app [here](https://github.com/settings/applications/new) and set authentication URL your server's hostname:port + `/auth/github/callback`, for example:
24+
**`PLUGIN_GITHUB_APP_SECRET`** Defaults to client secret of Strider-CD Github App
3025

31-
```
32-
http://your.strider.hostname:9999/auth/github/callback
33-
```
26+
**`PLUGIN_GITHUB_API_DOMAIN`** Defaults to `https://github.com`
3427

35-
- also make sure your github profile has a public email set
28+
**`PLUGIN_GITHUB_API_ENDPOINT`** Defaults to `https://api.github.com`
29+
30+
### Enterprise Setup
31+
32+
1) You'll need to create an Application on your GitHub Enterprise Server. Log in to GitHub Enterprise and navigate to
33+
`https://your-github-url.com/settings/applications/new` and set authentication URL to
34+
`https://your-strider-server:port/auth/github/callback`.
35+
2) Define the environment variables. Here is an example:
36+
```
37+
export SERVER_NAME="http://111.11.11.111:3000"
38+
export PLUGIN_GITHUB_APP_ID="a342d32c23c23"
39+
export PLUGIN_GITHUB_APP_SECRET="5af64a67af586847afbc6796769769d97a961"
40+
export PLUGIN_GITHUB_API_DOMAIN="https://github.my-organization.com"
41+
export PLUGIN_GITHUB_API_ENDPOINT="https://github.my-organization.com/api/v3"
42+
```
43+
**NOTE** `SERVER_NAME` must be the same exact host that you used for the 'Authentication URL' in step 1. For example,
44+
if you used `http://111.11.11.111:3000/auth/guthub/callback` in step 1, your `SERVER_NAME` **must** be
45+
`http://111.11.11.111:3000`. Also note that the protocol must be the same between the two (if you used `http://`
46+
in step 1, you must use `http://` in `SERVER_NAME` and not `https://`).
47+
3) Reboot strider and navigate link a github account as normal, you should see your enterprise repos!
48+
49+
#### Known Issues with Enterprise
50+
51+
- If you get 'Error: Could not fetch user profile': Somehow, passport will fail to retrieve the user profile unless all
52+
of the following are set. On GitHub Enterprise, log in to the profile you are trying to link to, and navigate to
53+
`/settings/profile`. Make sure the following are defined and set properly.
54+
- Public Email
55+
- Homepage URL
56+
57+
#### Known Issues with GitHub.com
58+
59+
- Make sure your github profile has a public email set
3660
* Go to https://github.com/settings/profile and select an email under "Public email".

lib/api.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ var superagent = require('superagent');
88
var url = require('url');
99
var util = require('util');
1010

11+
// todo this should use the `appConfig` object from ./webapp.js, but requiring it here would create a cyclical reference
1112
var GITHUB_API_ENDPOINT = process.env.PLUGIN_GITHUB_API_ENDPOINT || 'https://api.github.com';
1213

1314
module.exports = {
@@ -418,10 +419,10 @@ function getRepos(token, username, callback) {
418419
var group = this.group();
419420

420421
_.each(results, function (result) {
421-
var team_id = result.req.path.split('/');
422+
var team_id = result.req.path.match(/teams\/([0-9]*)/i)[1];
422423
debug("We get the following repo path: " + util.inspect(result.req.path));
423-
team_id = team_id[2]; //TODO: add Enterprise support. This might be different for Github Enterprise
424424

425+
// todo team_detail is unused
425426
var team_detail = team_detail_requests[parseInt(team_id, 10)];
426427
if (result.statusCode === 204) {
427428
pageinated_api_call('/teams/' + team_id + '/repos', token, group());
@@ -459,7 +460,7 @@ function getRepos(token, username, callback) {
459460
});
460461

461462
//If the user is a member of a team, we get a repository in repos
462-
//as well as team_repos. Thus we need to merge the two and de-dupe
463+
//as well as team_repos. Thus we need to merge the two and de-dupe
463464
repos = _.uniq(repos.concat(team_repos), false, function (item) {
464465
return item.id;
465466
});

lib/webapp.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ var utils = require('./utils');
88
var webhooks = require('./webhooks');
99

1010
module.exports = {
11-
// may be extended by strider, if it receives other config
1211
appConfig: {
13-
hostname: 'http://localhost:3000',
14-
appId: 'a3af4568e9d8ca4165fe',
15-
appSecret: '18651128b57787a3336094e2ba1af240dfe44f6c',
16-
apiDomain: 'https://github.com',
17-
apiEndpoint: 'https://api.github.com'
12+
hostname: process.env.SERVER_NAME || 'http://localhost:3000',
13+
// you only need to override these if you are connecting to github enterprise
14+
// if you are on github enterprise, you'll need to create a new app: http://github.whatever.com/applications/new
15+
appId: process.env.PLUGIN_GITHUB_APP_ID || 'a3af4568e9d8ca4165fe',
16+
appSecret: process.env.PLUGIN_GITHUB_APP_SECRET || '18651128b57787a3336094e2ba1af240dfe44f6c',
17+
// used for web auth
18+
apiDomain: process.env.PLUGIN_GITHUB_API_DOMAIN || 'https://github.com',
19+
// enterprise endpoint urls end in /api/v3
20+
apiEndpoint: process.env.PLUGIN_GITHUB_API_ENDPOINT || 'https://api.github.com'
1821
},
1922
fastFile: true,
2023
getBranches: function (account, config, project, done) {
@@ -57,6 +60,7 @@ module.exports = {
5760
api.getRepos(account.accessToken, account.login, next);
5861
},
5962

63+
// this attempts to connect to the github server with the stored credentials
6064
auth: function (passport, context) {
6165
var config = this.appConfig;
6266

0 commit comments

Comments
 (0)