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

Commit 14914e1

Browse files
committed
[Feature] Support for enterprise Github repository
Add a test, and make sure to support configuration that do not have the parameter
1 parent b8e5c4f commit 14914e1

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

src/spec/git/GithubURLs.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ describe('GithubRepo / GithubURLs', () => {
3636
});
3737
it('should throw on bad params', () => {
3838
assert.throws(() => {
39-
repo = new GithubRepo({repoOwner: null, repoProject: null}, null, null);
39+
repo = new GithubRepo({repoOwner: null, repoProject: null, githubHost: null}, null, null);
4040
});
4141
});
4242
it('should be constructor', () => {
43-
repo = new GithubRepo({repoOwner: 'foo', repoProject: 'bar'}, 'baz', gitTest.opts);
43+
repo = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'}, 'baz', gitTest.opts);
4444
urls = repo.urls;
4545
assert.ok(urls, 'instance');
4646
});
@@ -56,7 +56,7 @@ describe('GithubRepo / GithubURLs', () => {
5656
});
5757
});
5858
it('should return replaced urls', () => {
59-
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar'}, 'baz', gitTest.opts).urls;
59+
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'}, 'baz', gitTest.opts).urls;
6060
var api = 'https://api.github.com/repos/foo/bar';
6161
var raw = 'https://raw.githubusercontent.com/foo/bar';
6262
var base = 'https://github.com/foo/bar';
@@ -66,7 +66,7 @@ describe('GithubRepo / GithubURLs', () => {
6666
assert.strictEqual(urls.rawFile('2ece23298f06d9fb45772fdb1d38086918c80f44', 'sub/folder/file.txt'), rawFile, 'rawFile');
6767
});
6868
it('should return correctly replaced urls if repoConfig is modified after repo creation', () => {
69-
var repoConfig = {repoOwner: 'foo', repoProject: 'bar'};
69+
var repoConfig = {repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'};
7070
urls = new GithubRepo(repoConfig, 'baz', gitTest.opts).urls;
7171
repoConfig.repoOwner = 'correctOwner';
7272
repoConfig.repoProject = 'correctProject';
@@ -77,9 +77,19 @@ describe('GithubRepo / GithubURLs', () => {
7777
assert.strictEqual(urls.base(), base, 'base');
7878
});
7979
it('should return no trailing slash', () => {
80-
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar'}, 'baz', gitTest.opts).urls;
80+
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'}, 'baz', gitTest.opts).urls;
8181
assert.notMatch(urls.apiBranches(), /\/$/, 'apiBranches');
8282
assert.notMatch(urls.apiBranch('abc'), /\/$/, 'apiBranch');
8383
});
84+
it('should handle enterprise github urls', () => {
85+
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.mycompany.com'}, 'baz', gitTest.opts).urls;
86+
var api = 'https://github.mycompany.com/api/v3/repos/foo/bar';
87+
var raw = 'https://github.mycompany.com/foo/bar/raw';
88+
var base = 'https://github.mycompany.com/foo/bar';
89+
var rawFile = raw + '/2ece23298f06d9fb45772fdb1d38086918c80f44/sub/folder/file.txt';
90+
assert.strictEqual(urls.api(), api, 'api');
91+
assert.strictEqual(urls.base(), base, 'base');
92+
assert.strictEqual(urls.rawFile('2ece23298f06d9fb45772fdb1d38086918c80f44', 'sub/folder/file.txt'), rawFile, 'rawFile');
93+
});
8494
});
8595
});

src/tsd/context/Config.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,11 @@ class Config implements GithubRepoConfig {
149149
var json = this.otherFields;
150150
json.version = this.version;
151151
json.repo = this.repo;
152-
json.githubHost = this.githubHost;
152+
if (this.githubHost !== Const.githubHost) {
153+
// only write to config if the host is not github.com
154+
json.githubHost = this.githubHost;
155+
}
156+
153157
json.ref = this.ref;
154158
json.path = this.path;
155159

@@ -195,6 +199,10 @@ class Config implements GithubRepoConfig {
195199
this.version = json.version;
196200
this.repo = json.repo;
197201
this.githubHost = json.githubHost;
202+
if (!this.githubHost) {
203+
// when migrating from file that do not have this parameter make sure upgrade won't fail
204+
this.githubHost = Const.githubHost;
205+
}
198206
this.ref = json.ref;
199207
this.bundle = json.bundle;
200208
this.stats = (typeOf.isBoolean(json.stats) ? json.stats : Const.statsDefault);

src/tsd/schema/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ var schema = Joi.object({
2121
.default(Const.definitelyRepo)
2222
.required()
2323
.description('github repository "owner/name"'),
24+
githubHost: Joi
25+
.string()
26+
.default(Const.githubHost)
27+
.optional()
28+
.description('github url, used to specify github enteprise url'),
2429
ref: Joi
2530
.string().regex(/^[\w\.-]+(?:\/[\w\.-]+)*$/)
2631
.default(Const.mainBranch)

test/spec/git/fixtures/config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"repo": {
33
"repoOwner": "borisyankov",
44
"repoProject": "DefinitelyTyped",
5+
"githubHost": "github.com",
56
"ref": "master"
67
},
78
"data": {

0 commit comments

Comments
 (0)