Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Supports public and private git repos when using shorted repo syntax #2992

Merged
merged 2 commits into from
Apr 6, 2017
Merged
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
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://[email protected]/' + fragment.user + '/' + fragment.repo + '.git';
expect(GitHubResolver.getGitSSHUrl(fragment)).toBe(expected);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the getGitHTTPUrl test was actaully running getGitSSHUrl instead!

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://[email protected]/' + fragment.user + '/' + fragment.repo + '.git';
expect(GitLabResolver.getGitSSHUrl(fragment)).toBe(expected);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously the getGitHTTPUrl test was actaully running getGitSSHUrl instead!

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 @@ -196,12 +201,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