Skip to content

Commit

Permalink
Supports public and private git repos when using shorted repo syntax (y…
Browse files Browse the repository at this point in the history
…arnpkg#2992)

* Now supports public and private shortened git repos

* added tests for new method
  • Loading branch information
thedumbterminal authored and bestander committed Apr 6, 2017
1 parent d4b61a4 commit 2bc0d96
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
15 changes: 13 additions & 2 deletions __tests__/resolvers/exotics/bitbucket-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,25 @@ test('getTarballUrl should return the correct bitbucket tarball url', () => {
expect(BitBucketResolver.getTarballUrl(fragment, hash)).toBe(expected);
});

test('getGitHTTPUrl should return the correct git bitbucket url', () => {
test('getGitHTTPBaseUrl should return the correct git bitbucket base url', () => {
const fragment: ExplodedFragment = {
user: 'foo',
repo: 'bar',
hash: '',
};

const expected = _bitBucketBase + fragment.user + '/' + fragment.repo + '.git';
const expected = _bitBucketBase + fragment.user + '/' + fragment.repo;
expect(BitBucketResolver.getGitHTTPBaseUrl(fragment)).toBe(expected);
});

test('getGitHTTPUrl should append ".git" to the HTTP base URL', () => {
const fragment: ExplodedFragment = {
user: 'foo',
repo: 'bar',
hash: '',
};

const expected = BitBucketResolver.getGitHTTPBaseUrl(fragment) + '.git';
expect(BitBucketResolver.getGitHTTPUrl(fragment)).toBe(expected);
});

Expand Down
17 changes: 14 additions & 3 deletions __tests__/resolvers/exotics/github-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ test('getGitSSHUrl with no hash', () => {
expect(gitSSHUrl).toContain('some-user');
});

test('getGitHTTPUrl should return the correct git github SSH url', () => {
test('getGitHTTPBaseUrl should return the correct git github HTTP base url', () => {
const fragment: ExplodedFragment = {
user: 'foo',
repo: 'bar',
hash: '',
};

const expected = 'git+ssh://git@github.com/' + fragment.user + '/' + fragment.repo + '.git';
expect(GitHubResolver.getGitSSHUrl(fragment)).toBe(expected);
const expected = 'https://github.com/' + fragment.user + '/' + fragment.repo;
expect(GitHubResolver.getGitHTTPBaseUrl(fragment)).toBe(expected);
});

test('getGitHTTPUrl should append ".git" to the HTTP base URL', () => {
const fragment: ExplodedFragment = {
user: 'foo',
repo: 'bar',
hash: '',
};

const expected = GitHubResolver.getGitHTTPBaseUrl(fragment) + '.git';
expect(GitHubResolver.getGitHTTPUrl(fragment)).toBe(expected);
});

test('getGitSSHUrl should return URL containing protocol', () => {
Expand Down
17 changes: 14 additions & 3 deletions __tests__/resolvers/exotics/gitlab-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,26 @@ test('getGitSSHUrl with no hash', () => {
expect(gitSSHUrl).toContain('some-user');
});

test('getGitHTTPUrl should return the correct git gitlab SSH url', () => {
test('getGitHTTPBaseUrl should return the correct git gitlab HTTP base url', () => {
const fragment: ExplodedFragment = {
user: 'foo',
repo: 'bar',
hash: '',
};

const expected = 'git+ssh://git@gitlab.com/' + fragment.user + '/' + fragment.repo + '.git';
expect(GitLabResolver.getGitSSHUrl(fragment)).toBe(expected);
const expected = 'https://gitlab.com/' + fragment.user + '/' + fragment.repo;
expect(GitLabResolver.getGitHTTPBaseUrl(fragment)).toBe(expected);
});

test('getGitHTTPUrl should append ".git" to the HTTP base URL', () => {
const fragment: ExplodedFragment = {
user: 'foo',
repo: 'bar',
hash: '',
};

const expected = GitLabResolver.getGitHTTPBaseUrl(fragment) + '.git';
expect(GitLabResolver.getGitHTTPUrl(fragment)).toBe(expected);
});

test('getGitSSHUrl should return URL containing protocol', () => {
Expand Down
6 changes: 5 additions & 1 deletion src/resolvers/exotics/bitbucket-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ export default class BitbucketResolver extends HostedGitResolver {
return `https://${this.hostname}/${parts.user}/${parts.repo}/get/${hash}.tar.gz`;
}

static getGitHTTPBaseUrl(parts: ExplodedFragment): string {
return `https://${this.hostname}/${parts.user}/${parts.repo}`;
}

static getGitHTTPUrl(parts: ExplodedFragment): string {
return `https://${this.hostname}/${parts.user}/${parts.repo}.git`;
return `${BitbucketResolver.getGitHTTPBaseUrl(parts)}.git`;
}

static getGitSSHUrl(parts: ExplodedFragment): string {
Expand Down
6 changes: 5 additions & 1 deletion src/resolvers/exotics/github-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ export default class GitHubResolver extends HostedGitResolver {
`${parts.hash ? '#' + decodeURIComponent(parts.hash) : ''}`;
}

static getGitHTTPBaseUrl(parts: ExplodedFragment): string {
return `https://${this.hostname}/${parts.user}/${parts.repo}`;
}

static getGitHTTPUrl(parts: ExplodedFragment): string {
return `https://${this.hostname}/${parts.user}/${parts.repo}.git`;
return `${GitHubResolver.getGitHTTPBaseUrl(parts)}.git`;
}

static getHTTPFileUrl(parts: ExplodedFragment, filename: string, commit: string): string {
Expand Down
6 changes: 5 additions & 1 deletion src/resolvers/exotics/gitlab-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ export default class GitLabResolver extends HostedGitResolver {
return `https://${this.hostname}/${parts.user}/${parts.repo}/repository/archive.tar.gz?ref=${hash}`;
}

static getGitHTTPBaseUrl(parts: ExplodedFragment): string {
return `https://${this.hostname}/${parts.user}/${parts.repo}`;
}

static getGitHTTPUrl(parts: ExplodedFragment): string {
return `https://${this.hostname}/${parts.user}/${parts.repo}.git`;
return `${GitLabResolver.getGitHTTPBaseUrl(parts)}.git`;
}

static getGitSSHUrl(parts: ExplodedFragment): string {
Expand Down
8 changes: 7 additions & 1 deletion src/resolvers/exotics/hosted-git-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ export default class HostedGitResolver extends ExoticResolver {
throw new Error('Not implemented');
}

static getGitHTTPBaseUrl(exploded: ExplodedFragment): string {
exploded;
throw new Error('Not implemented');
}

static getGitSSHUrl(exploded: ExplodedFragment): string {
exploded;
throw new Error('Not implemented');
Expand Down Expand Up @@ -197,12 +202,13 @@ export default class HostedGitResolver extends ExoticResolver {

async resolve(): Promise<Manifest> {
const httpUrl = this.constructor.getGitHTTPUrl(this.exploded);
const httpBaseUrl = this.constructor.getGitHTTPBaseUrl(this.exploded);
const sshUrl = this.constructor.getGitSSHUrl(this.exploded);

// If we can access the files over HTTP then we should as it's MUCH faster than git
// archive and tarball unarchiving. The HTTP API is only available for public repos
// though.
if (await this.hasHTTPCapability(httpUrl)) {
if (await this.hasHTTPCapability(httpBaseUrl)) {
return await this.resolveOverHTTP(httpUrl);
}

Expand Down

0 comments on commit 2bc0d96

Please sign in to comment.