From f1d4d08d51100d83073cc0343dc7841f28a89989 Mon Sep 17 00:00:00 2001 From: Chad Hietala Date: Wed, 13 Jul 2022 10:38:02 -0400 Subject: [PATCH] Add more Github Enterprise URLs This PR adds support for more github enterprise URLs. They offer: ``` *.ghe.com *.github.us ``` https://github.com/github/docs/blob/5f4ef9a6217181efc12e67463894783496fb0c79/content/admin/identity-and-access-management/using-saml-for-enterprise-iam/saml-configuration-reference.md#saml-response-requirements --- src/lib/converter/utils/repository.ts | 14 ++++++++++++++ src/test/Repository.test.ts | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/lib/converter/utils/repository.ts b/src/lib/converter/utils/repository.ts index 99ba4cca1c..bbe220e514 100644 --- a/src/lib/converter/utils/repository.ts +++ b/src/lib/converter/utils/repository.ts @@ -82,6 +82,20 @@ export class Repository { ); } + // Github Enterprise + if (!match) { + match = /(\w+\.ghe.com)[:/]([^/]+)\/(.*)/.exec( + repoLinks[i] + ); + } + + // Github Enterprise + if (!match) { + match = /(\w+\.github.us)[:/]([^/]+)\/(.*)/.exec( + repoLinks[i] + ); + } + if (!match) { match = /(bitbucket.org)[:/]([^/]+)\/(.*)/.exec(repoLinks[i]); } diff --git a/src/test/Repository.test.ts b/src/test/Repository.test.ts index d1e2067dc5..a2c40b774f 100644 --- a/src/test/Repository.test.ts +++ b/src/test/Repository.test.ts @@ -46,6 +46,32 @@ describe("Repository", function () { equal(repository.type, RepositoryType.GitHub); }); + it("handles a ghe.com URL", function () { + const mockRemotes = [ + "ssh://org@bigcompany.ghe.com/joebloggs/foobar.git", + ]; + + const repository = new Repository("", "", mockRemotes); + + equal(repository.hostname, "bigcompany.ghe.com"); + equal(repository.user, "joebloggs"); + equal(repository.project, "foobar"); + equal(repository.type, RepositoryType.GitHub); + }); + + it("handles a github.us URL", function () { + const mockRemotes = [ + "ssh://org@bigcompany.github.us/joebloggs/foobar.git", + ]; + + const repository = new Repository("", "", mockRemotes); + + equal(repository.hostname, "bigcompany.github.us"); + equal(repository.user, "joebloggs"); + equal(repository.project, "foobar"); + equal(repository.type, RepositoryType.GitHub); + }); + it("handles a Bitbucket HTTPS URL", function () { const mockRemotes = [ "https://joebloggs@bitbucket.org/joebloggs/foobar.git",