diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-03-25 15:12:22 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-03-25 15:12:22 -0400 |
| commit | 18fd0bc59958dd73f02ac7a98cb5995f83e6f1de (patch) | |
| tree | b7dd7374364d23c08a542687b7f9033c9e271bc5 /src/url-helper.ts | |
| parent | e8e736100be926c1708f65609a1458e5e36bda31 (diff) | |
changes to support ghes alpha release (#199)
Diffstat (limited to 'src/url-helper.ts')
| -rw-r--r-- | src/url-helper.ts | 28 |
1 files changed, 28 insertions, 0 deletions
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') +} |
