diff --git a/src/lib/converter/utils/repository.ts b/src/lib/converter/utils/repository.ts index 99ba4cca1..b1087d80b 100644 --- a/src/lib/converter/utils/repository.ts +++ b/src/lib/converter/utils/repository.ts @@ -71,7 +71,7 @@ export class Repository { for (let i = 0, c = repoLinks.length; i < c; i++) { let match = - /(github(?:\.[a-z]+)*\.[a-z]{2,})[:/]([^/]+)\/(.*)/.exec( + /(github(?!.us)(?:\.[a-z]+)*\.[a-z]{2,})[:/]([^/]+)\/(.*)/.exec( repoLinks[i] ); @@ -82,6 +82,16 @@ 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 d1e2067dc..a2c40b774 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",