From 011808a5b261dde645fdb233859febfda574b6d7 Mon Sep 17 00:00:00 2001 From: Thomas Jaggi Date: Thu, 3 Nov 2016 13:53:59 +0100 Subject: [PATCH 1/2] Resolve GitHub http urls with commit hash --- __tests__/resolvers/exotics/github-resolver.js | 11 +++++++++++ src/resolvers/exotics/github-resolver.js | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/__tests__/resolvers/exotics/github-resolver.js b/__tests__/resolvers/exotics/github-resolver.js index 368a373433..0abaf2990e 100644 --- a/__tests__/resolvers/exotics/github-resolver.js +++ b/__tests__/resolvers/exotics/github-resolver.js @@ -38,6 +38,17 @@ test('getGitHTTPUrl should return the correct git github SSH url', () => { expect(GitHubResolver.getGitSSHUrl(fragment)).toBe(expected); }); +test('getGitHTTPUrl with hash should return the correct git github SSH url', () => { + const fragment: ExplodedFragment = { + user: 'foo', + repo: 'bar', + hash: 'hash', + }; + + const expected = 'git+ssh://git@github.com/' + fragment.user + '/' + fragment.repo + '.git#hash'; + expect(GitHubResolver.getGitSSHUrl(fragment)).toBe(expected); +}); + test('getGitSSHUrl should return URL containing protocol', () => { const gitSSHUrl = GitHubResolver.getGitSSHUrl({ hash: '', diff --git a/src/resolvers/exotics/github-resolver.js b/src/resolvers/exotics/github-resolver.js index fde3867e1b..3dbf8be638 100644 --- a/src/resolvers/exotics/github-resolver.js +++ b/src/resolvers/exotics/github-resolver.js @@ -31,7 +31,8 @@ export default class GitHubResolver extends HostedGitResolver { } static getGitHTTPUrl(parts: ExplodedFragment): string { - return `https://${this.hostname}/${parts.user}/${parts.repo}.git`; + return `https://${this.hostname}/${parts.user}/${parts.repo}.git` + + `${parts.hash ? '#' + decodeURIComponent(parts.hash) : ''}`; } static getHTTPFileUrl(parts: ExplodedFragment, filename: string, commit: string): string { From 63c370206e745b77e7f8cdbe8e83daacb26c3013 Mon Sep 17 00:00:00 2001 From: Thomas Jaggi Date: Thu, 3 Nov 2016 14:00:28 +0100 Subject: [PATCH 2/2] GitHub url resolver: Fix newly added test --- __tests__/resolvers/exotics/github-resolver.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/resolvers/exotics/github-resolver.js b/__tests__/resolvers/exotics/github-resolver.js index 0abaf2990e..dfeca50b3c 100644 --- a/__tests__/resolvers/exotics/github-resolver.js +++ b/__tests__/resolvers/exotics/github-resolver.js @@ -38,15 +38,15 @@ test('getGitHTTPUrl should return the correct git github SSH url', () => { expect(GitHubResolver.getGitSSHUrl(fragment)).toBe(expected); }); -test('getGitHTTPUrl with hash should return the correct git github SSH url', () => { +test('getGitHTTPUrl with hash should return the correct git url', () => { const fragment: ExplodedFragment = { user: 'foo', repo: 'bar', hash: 'hash', }; - const expected = 'git+ssh://git@github.com/' + fragment.user + '/' + fragment.repo + '.git#hash'; - expect(GitHubResolver.getGitSSHUrl(fragment)).toBe(expected); + const expected = 'https://github.com/' + fragment.user + '/' + fragment.repo + '.git#hash'; + expect(GitHubResolver.getGitHTTPUrl(fragment)).toBe(expected); }); test('getGitSSHUrl should return URL containing protocol', () => {