Skip to content
This repository was archived by the owner on Apr 30, 2019. It is now read-only.

Commit b8e5c4f

Browse files
committed
[Feature] Support for enterprise Github repository
Add an extra parameters in the tsd.json file to support specifying the url to your github host. Parameter name is githubHost and by default will point to github.com (so no change to current behavior). If an enterprise github url is specified instead then the url for requests will be adapted to follow the scheme of enterprise github.
1 parent d780369 commit b8e5c4f

File tree

5 files changed

+40
-16
lines changed

5 files changed

+40
-16
lines changed

src/getContent.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ function getContent(options): Promise<any> {
7171
var ret: any = {
7272
repo: api.context.config.repo,
7373
ref: api.context.config.ref,
74+
githubHost: api.context.config.githubHost,
7475
count: content.length,
7576
time: new Date().toISOString()
7677
};
7778
ret.urls = {
78-
def: 'https://github.com/' + ret.repo + '/blob/' + ret.ref + '/{path}'
79+
def: 'https://' + ret.githubHost + '/' + ret.repo + '/blob/' + ret.ref + '/{path}'
7980
};
8081
ret.content = content;
8182
return ret;

src/git/GithubRepoConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// <reference path="./_ref.d.ts" />
22

33
interface GithubRepoConfig {
4+
githubHost: string;
45
repoOwner: string;
56
repoProject: string;
67
}

src/git/GithubURLs.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,50 @@ class GithubURLs extends URLManager {
1616
private _apiBase: string = 'https://api.github.com';
1717
private _api: string = 'https://api.github.com/repos/{owner}/{project}';
1818
private _raw: string = 'https://raw.githubusercontent.com/{owner}/{project}';
19+
20+
private _enterpriseBase: string = 'https://{githubHost}/{owner}/{project}';
21+
private _enterpriseApiBase: string = 'https://{githubHost}/api/v3';
22+
private _enterpriseApi: string = 'https://{githubHost}/api/v3/repos/{owner}/{project}';
23+
private _enterpriseRaw: string = 'https://{githubHost}/{owner}/{project}/raw';
1924
private _repo: GithubRepo;
2025

2126
constructor(repo: GithubRepo) {
2227
super();
2328
assertVar(repo, 'object', 'repo');
2429

2530
this._repo = repo;
31+
var base: string = this._base;
32+
var raw: string = this._raw;
33+
var api: string = this._api;
34+
var apiBase: string = this._apiBase;
35+
if (this._repo.config.githubHost !== 'github.com') {
36+
// We are working with an enterprise github
37+
base = this._enterpriseBase;
38+
raw = this._enterpriseRaw;
39+
api = this._enterpriseApi;
40+
apiBase = this._enterpriseApiBase;
41+
}
2642
// externalise later
27-
this.addTemplate('base', this._base);
43+
this.addTemplate('base', base);
2844

29-
this.addTemplate('raw', this._raw);
30-
this.addTemplate('rawFile', this._raw + '/{+ref}/{+path}');
45+
this.addTemplate('raw', raw);
46+
this.addTemplate('rawFile', raw + '/{+ref}/{+path}');
3147

32-
this.addTemplate('htmlFile', this._base + '/blob/{ref}/{+path}');
48+
this.addTemplate('htmlFile', base + '/blob/{ref}/{+path}');
3349

34-
this.addTemplate('api', this._api);
35-
this.addTemplate('apiTree', this._api + '/git/trees/{tree}?recursive={recursive}');
36-
this.addTemplate('apiBranch', this._api + '/branches/{branch}');
37-
this.addTemplate('apiBranches', this._api + '/branches');
38-
this.addTemplate('apiCommit', this._api + '/commits/{commit}');
39-
this.addTemplate('apiPathCommits', this._api + '/commits?path={path}');
40-
this.addTemplate('apiBlob', this._api + '/git/blobs/{blob}');
41-
this.addTemplate('rateLimit', this._apiBase + '/rate_limit');
50+
this.addTemplate('api', api);
51+
this.addTemplate('apiTree', api + '/git/trees/{tree}?recursive={recursive}');
52+
this.addTemplate('apiBranch', api + '/branches/{branch}');
53+
this.addTemplate('apiBranches', api + '/branches');
54+
this.addTemplate('apiCommit', api + '/commits/{commit}');
55+
this.addTemplate('apiPathCommits', api + '/commits?path={path}');
56+
this.addTemplate('apiBlob', api + '/git/blobs/{blob}');
57+
this.addTemplate('rateLimit', apiBase + '/rate_limit');
4258
}
4359

4460
getURL(id: string, vars?: any): string {
4561
this.setVars({
62+
githubHost: this._repo.config.githubHost,
4663
owner: this._repo.config.repoOwner,
4764
project: this._repo.config.repoProject
4865
});

src/tsd/context/Config.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Config implements GithubRepoConfig {
4141
path: string;
4242
version: string;
4343
repo: string;
44+
githubHost: string;
4445
ref: string;
4546
stats: boolean;
4647
bundle: string;
@@ -61,6 +62,7 @@ class Config implements GithubRepoConfig {
6162
this.path = Const.typingsDir;
6263
this.version = Const.configVersion;
6364
this.repo = Const.definitelyRepo;
65+
this.githubHost = Const.githubHost;
6466
this.ref = Const.mainBranch;
6567
this.stats = Const.statsDefault;
6668
this.otherFields = {};
@@ -147,6 +149,7 @@ class Config implements GithubRepoConfig {
147149
var json = this.otherFields;
148150
json.version = this.version;
149151
json.repo = this.repo;
152+
json.githubHost = this.githubHost;
150153
json.ref = this.ref;
151154
json.path = this.path;
152155

@@ -191,6 +194,7 @@ class Config implements GithubRepoConfig {
191194
this.path = json.path;
192195
this.version = json.version;
193196
this.repo = json.repo;
197+
this.githubHost = json.githubHost;
194198
this.ref = json.ref;
195199
this.bundle = json.bundle;
196200
this.stats = (typeOf.isBoolean(json.stats) ? json.stats : Const.statsDefault);
@@ -205,9 +209,9 @@ class Config implements GithubRepoConfig {
205209
});
206210
}
207211

208-
var reservedFields = ['path', 'version', 'repo', 'ref', 'bundle', 'stats', 'installed'];
209-
var otherFieldKeys = Object.keys(json).filter(function(key) { return reservedFields.indexOf(key) === -1; } );
210-
this.otherFields = otherFieldKeys.reduce(function(fields, key) {
212+
var reservedFields = ['path', 'version', 'repo', 'githubHost', 'ref', 'bundle', 'stats', 'installed'];
213+
var otherFieldKeys = Object.keys(json).filter(function (key) { return reservedFields.indexOf(key) === -1; });
214+
this.otherFields = otherFieldKeys.reduce(function (fields, key) {
211215
fields[key] = json[key];
212216
return fields;
213217
}, {});

src/tsd/context/Const.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Const = {
1414

1515
configVersion: 'v4',
1616
definitelyRepo: 'borisyankov/DefinitelyTyped',
17+
githubHost: 'github.com',
1718
mainBranch: 'master',
1819
statsDefault: true,
1920

0 commit comments

Comments
 (0)