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 | |
| parent | e8e736100be926c1708f65609a1458e5e36bda31 (diff) | |
changes to support ghes alpha release (#199)
Diffstat (limited to 'src')
| -rw-r--r-- | src/git-auth-helper.ts | 16 | ||||
| -rw-r--r-- | src/git-source-provider.ts | 11 | ||||
| -rw-r--r-- | src/github-api-helper.ts | 3 | ||||
| -rw-r--r-- | src/url-helper.ts | 28 |
4 files changed, 43 insertions, 15 deletions
diff --git a/src/git-auth-helper.ts b/src/git-auth-helper.ts index 06e8912..92763b8 100644 --- a/src/git-auth-helper.ts +++ b/src/git-auth-helper.ts @@ -7,12 +7,12 @@ import * as os from 'os' import * as path from 'path' import * as regexpHelper from './regexp-helper' import * as stateHelper from './state-helper' +import * as urlHelper from './url-helper' import {default as uuid} from 'uuid/v4' import {IGitCommandManager} from './git-command-manager' import {IGitSourceSettings} from './git-source-settings' const IS_WINDOWS = process.platform === 'win32' -const HOSTNAME = 'github.com' const SSH_COMMAND_KEY = 'core.sshCommand' export interface IGitAuthHelper { @@ -33,15 +33,15 @@ export function createAuthHelper( class GitAuthHelper { private readonly git: IGitCommandManager private readonly settings: IGitSourceSettings - private readonly tokenConfigKey: string = `http.https://${HOSTNAME}/.extraheader` + private readonly tokenConfigKey: string + private readonly tokenConfigValue: string private readonly tokenPlaceholderConfigValue: string - private readonly insteadOfKey: string = `url.https://${HOSTNAME}/.insteadOf` - private readonly insteadOfValue: string = `git@${HOSTNAME}:` + private readonly insteadOfKey: string + private readonly insteadOfValue: string private sshCommand = '' private sshKeyPath = '' private sshKnownHostsPath = '' private temporaryHomePath = '' - private tokenConfigValue: string constructor( gitCommandManager: IGitCommandManager, @@ -51,6 +51,8 @@ class GitAuthHelper { this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings) // Token auth header + const serverUrl = urlHelper.getServerUrl() + this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT] const basicCredential = Buffer.from( `x-access-token:${this.settings.authToken}`, 'utf8' @@ -58,6 +60,10 @@ class GitAuthHelper { core.setSecret(basicCredential) this.tokenPlaceholderConfigValue = `AUTHORIZATION: basic ***` this.tokenConfigValue = `AUTHORIZATION: basic ${basicCredential}` + + // Instead of SSH URL + this.insteadOfKey = `url.${serverUrl.origin}/.insteadOf` // "origin" is SCHEME://HOSTNAME[:PORT] + this.insteadOfValue = `git@${serverUrl.hostname}:` } async configureAuth(): Promise<void> { diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts index 4bce702..85806bb 100644 --- a/src/git-source-provider.ts +++ b/src/git-source-provider.ts @@ -8,23 +8,16 @@ import * as io from '@actions/io' import * as path from 'path' import * as refHelper from './ref-helper' import * as stateHelper from './state-helper' +import * as urlHelper from './url-helper' import {IGitCommandManager} from './git-command-manager' import {IGitSourceSettings} from './git-source-settings' -const hostname = 'github.com' - export async function getSource(settings: IGitSourceSettings): Promise<void> { // Repository URL core.info( `Syncing repository: ${settings.repositoryOwner}/${settings.repositoryName}` ) - const repositoryUrl = settings.sshKey - ? `git@${hostname}:${encodeURIComponent( - settings.repositoryOwner - )}/${encodeURIComponent(settings.repositoryName)}.git` - : `https://${hostname}/${encodeURIComponent( - settings.repositoryOwner - )}/${encodeURIComponent(settings.repositoryName)}` + const repositoryUrl = urlHelper.getFetchUrl(settings) // Remove conflicting file path if (fsHelper.fileExistsSync(settings.repositoryPath)) { diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts index 83a2b86..df11a85 100644 --- a/src/github-api-helper.ts +++ b/src/github-api-helper.ts @@ -6,6 +6,7 @@ import * as io from '@actions/io' import * as path from 'path' import * as retryHelper from './retry-helper' import * as toolCache from '@actions/tool-cache' +import * as urlHelper from './url-helper' import {default as uuid} from 'uuid/v4' import {ReposGetArchiveLinkParams} from '@octokit/rest' @@ -74,7 +75,7 @@ async function downloadArchive( ref: string, commit: string ): Promise<Buffer> { - const octokit = new github.GitHub(authToken) + const octokit = new github.GitHub(authToken, {baseUrl: urlHelper.getApiUrl()}) const params: ReposGetArchiveLinkParams = { owner: owner, repo: repo, 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') +} |
