From 18fd0bc59958dd73f02ac7a98cb5995f83e6f1de Mon Sep 17 00:00:00 2001 From: eric sciple Date: Wed, 25 Mar 2020 15:12:22 -0400 Subject: changes to support ghes alpha release (#199) --- src/url-helper.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/url-helper.ts (limited to 'src/url-helper.ts') diff --git a/src/url-helper.ts b/src/url-helper.ts new file mode 100644 index 0000000..3e0e142 --- /dev/null +++ b/src/url-helper.ts @@ -0,0 +1,28 @@ +import * as assert from 'assert' +import {IGitSourceSettings} from './git-source-settings' +import {URL} from 'url' + +export function getApiUrl(): string { + return process.env['GITHUB_API_URL'] || 'https://api.github.com' +} + +export function getFetchUrl(settings: IGitSourceSettings): string { + assert.ok( + settings.repositoryOwner, + 'settings.repositoryOwner must be defined' + ) + assert.ok(settings.repositoryName, 'settings.repositoryName must be defined') + const serviceUrl = getServerUrl() + const encodedOwner = encodeURIComponent(settings.repositoryOwner) + const encodedName = encodeURIComponent(settings.repositoryName) + if (settings.sshKey) { + return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git` + } + + // "origin" is SCHEME://HOSTNAME[:PORT] + return `${serviceUrl.origin}/${encodedOwner}/${encodedName}` +} + +export function getServerUrl(): URL { + return new URL(process.env['GITHUB_URL'] || 'https://github.com') +} -- cgit v1.2.3