From 706b4133539a67033b7ff0ec570aba2aa5e58f3c Mon Sep 17 00:00:00 2001 From: Alex Collins Date: Mon, 23 Sep 2019 13:24:17 -0700 Subject: [PATCH] Adds support for Github Enterprise URLs (#2344) --- ui/src/app/shared/components/urls.test.ts | 12 ++++++++++++ ui/src/app/shared/components/urls.ts | 10 ++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ui/src/app/shared/components/urls.test.ts b/ui/src/app/shared/components/urls.test.ts index ecb0835703..9e6f5e3454 100644 --- a/ui/src/app/shared/components/urls.test.ts +++ b/ui/src/app/shared/components/urls.test.ts @@ -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( diff --git a/ui/src/app/shared/components/urls.ts b/ui/src/app/shared/components/urls.ts index 1954153368..63e9d7cdf0 100644 --- a/ui/src/app/shared/components/urls.ts +++ b/ui/src/app/shared/components/urls.ts @@ -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; }