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

allow configuring protocol of Github repository url #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/getContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function getContent(options): Promise<any> {
time: new Date().toISOString()
};
ret.urls = {
def: 'https://' + ret.githubHost + '/' + ret.repo + '/blob/' + ret.ref + '/{path}'
def: ret.githubHost + '/' + ret.repo + '/blob/' + ret.ref + '/{path}'
};
ret.content = content;
return ret;
Expand Down
10 changes: 5 additions & 5 deletions src/git/GithubURLs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class GithubURLs extends URLManager {
private _api: string = 'https://api.github.com/repos/{owner}/{project}';
private _raw: string = 'https://raw.githubusercontent.com/{owner}/{project}';

private _enterpriseBase: string = 'https://{githubHost}/{owner}/{project}';
private _enterpriseApiBase: string = 'https://{githubHost}/api/v3';
private _enterpriseApi: string = 'https://{githubHost}/api/v3/repos/{owner}/{project}';
private _enterpriseRaw: string = 'https://{githubHost}/{owner}/{project}/raw';
private _enterpriseBase: string = '{+githubHost}/{owner}/{project}';
private _enterpriseApiBase: string = '{+githubHost}/api/v3';
private _enterpriseApi: string = '{+githubHost}/api/v3/repos/{owner}/{project}';
private _enterpriseRaw: string = '{+githubHost}/{owner}/{project}/raw';
private _repo: GithubRepo;

constructor(repo: GithubRepo) {
Expand All @@ -32,7 +32,7 @@ class GithubURLs extends URLManager {
var raw: string = this._raw;
var api: string = this._api;
var apiBase: string = this._apiBase;
if (this._repo.config.githubHost !== 'github.com') {
if (this._repo.config.githubHost !== 'https://github.com') {
// We are working with an enterprise github
base = this._enterpriseBase;
raw = this._enterpriseRaw;
Expand Down
10 changes: 5 additions & 5 deletions src/spec/git/GithubURLs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('GithubRepo / GithubURLs', () => {
});
});
it('should be constructor', () => {
repo = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'}, 'baz', gitTest.opts);
repo = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'}, 'baz', gitTest.opts);
urls = repo.urls;
assert.ok(urls, 'instance');
});
Expand All @@ -56,7 +56,7 @@ describe('GithubRepo / GithubURLs', () => {
});
});
it('should return replaced urls', () => {
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'}, 'baz', gitTest.opts).urls;
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'}, 'baz', gitTest.opts).urls;
var api = 'https://api.github.com/repos/foo/bar';
var raw = 'https://raw.githubusercontent.com/foo/bar';
var base = 'https://github.com/foo/bar';
Expand All @@ -66,7 +66,7 @@ describe('GithubRepo / GithubURLs', () => {
assert.strictEqual(urls.rawFile('2ece23298f06d9fb45772fdb1d38086918c80f44', 'sub/folder/file.txt'), rawFile, 'rawFile');
});
it('should return correctly replaced urls if repoConfig is modified after repo creation', () => {
var repoConfig = {repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'};
var repoConfig = {repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'};
urls = new GithubRepo(repoConfig, 'baz', gitTest.opts).urls;
repoConfig.repoOwner = 'correctOwner';
repoConfig.repoProject = 'correctProject';
Expand All @@ -77,12 +77,12 @@ describe('GithubRepo / GithubURLs', () => {
assert.strictEqual(urls.base(), base, 'base');
});
it('should return no trailing slash', () => {
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.com'}, 'baz', gitTest.opts).urls;
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.com'}, 'baz', gitTest.opts).urls;
assert.notMatch(urls.apiBranches(), /\/$/, 'apiBranches');
assert.notMatch(urls.apiBranch('abc'), /\/$/, 'apiBranch');
});
it('should handle enterprise github urls', () => {
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'github.mycompany.com'}, 'baz', gitTest.opts).urls;
urls = new GithubRepo({repoOwner: 'foo', repoProject: 'bar', githubHost: 'https://github.mycompany.com'}, 'baz', gitTest.opts).urls;
var api = 'https://github.mycompany.com/api/v3/repos/foo/bar';
var raw = 'https://github.mycompany.com/foo/bar/raw';
var base = 'https://github.mycompany.com/foo/bar';
Expand Down
2 changes: 1 addition & 1 deletion src/tsd/context/Const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Const = {

configVersion: 'v4',
definitelyRepo: 'borisyankov/DefinitelyTyped',
githubHost: 'github.com',
githubHost: 'https://github.com',
mainBranch: 'master',
statsDefault: true,

Expand Down
2 changes: 1 addition & 1 deletion test/spec/git/fixtures/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"repo": {
"repoOwner": "borisyankov",
"repoProject": "DefinitelyTyped",
"githubHost": "github.com",
"githubHost": "https://github.com",
"ref": "master"
},
"data": {
Expand Down