diff --git a/__tests__/resolvers/exotics/github-resolver.js b/__tests__/resolvers/exotics/github-resolver.js index 368a373433..dfeca50b3c 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 url', () => { + const fragment: ExplodedFragment = { + user: 'foo', + repo: 'bar', + hash: 'hash', + }; + + const expected = 'https://github.com/' + fragment.user + '/' + fragment.repo + '.git#hash'; + expect(GitHubResolver.getGitHTTPUrl(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 {