Adds support for Github Enterprise URLs (#2344)

This commit is contained in:
Alex Collins 2019-09-23 13:24:17 -07:00 committed by GitHub
parent c4203f7989
commit 706b413353
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 4 deletions

View file

@ -2,9 +2,12 @@ import {repoUrl, revisionUrl} from './urls';
function testExample(http: string, ssl: string, revision: string, expectedRepoUrl: string, expectedRevisionUrl: string) {
expect(repoUrl(http)).toBe(expectedRepoUrl);
expect(repoUrl(ssl)).toBe(expectedRepoUrl);
expect(revisionUrl(http, revision)).toBe(expectedRevisionUrl);
expect(revisionUrl(ssl, revision)).toBe(expectedRevisionUrl);
expect(repoUrl(http)).toBe(expectedRepoUrl);
expect(revisionUrl(http, revision)).toBe(expectedRevisionUrl);
expect(revisionUrl(ssl, revision)).toBe(expectedRevisionUrl);
}
test('github.com', () => {
@ -16,6 +19,15 @@ test('github.com', () => {
'https://github.com/argoproj/argo-cd/commit/024dee09f543ce7bb5af7ca50260504d89dfda94');
});
// for enterprise github installations
test('github.my-enterprise.com', () => {
testExample(
'https://github.my-enterprise.com/my-org/my-repo.git',
'git@github.my-enterprise.com:my-org/my-repo.git',
'a06f2be80a4da89abb8ced904beab75b3ec6db0e',
'https://github.my-enterprise.com/my-org/my-repo',
'https://github.my-enterprise.com/my-org/my-repo/commit/a06f2be80a4da89abb8ced904beab75b3ec6db0e');
});
test('gitlab.com', () => {
testExample(

View file

@ -1,7 +1,9 @@
import {GitUrl} from 'git-url-parse';
const GitUrlParse = require('git-url-parse');
function supportedSource(source: string): boolean {
return ['github.com', 'gitlab.com', 'bitbucket.org'].indexOf(source) >= 0;
function supportedSource(parsed: GitUrl): boolean {
return parsed.resource.startsWith('github') || ['gitlab.com', 'bitbucket.org'].indexOf(parsed.source) >= 0;
}
function protocol(proto: string): string {
@ -11,7 +13,7 @@ function protocol(proto: string): string {
export function repoUrl(url: string): string {
const parsed = GitUrlParse(url);
if (!supportedSource(parsed.source)) {
if (!supportedSource(parsed)) {
return null;
}
@ -22,7 +24,7 @@ export function revisionUrl(url: string, revision: string): string {
const parsed = GitUrlParse(url);
if (!supportedSource(parsed.source)) {
if (!supportedSource(parsed)) {
return null;
}