1
0
Fork 0
mirror of https://code.forgejo.org/actions/checkout.git synced 2024-12-01 08:29:15 +01:00

add config option to set github host

This commit is contained in:
GABeech 2022-06-14 22:12:53 -04:00
parent 2541b1294d
commit 2202a283a7
3 changed files with 13 additions and 3 deletions

View file

@ -52,7 +52,7 @@ class GitAuthHelper {
this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings) this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings)
// Token auth header // Token auth header
const serverUrl = urlHelper.getServerUrl() const serverUrl = urlHelper.getServerUrl(gitSourceSettings?.setHost)
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT] this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT]
const basicCredential = Buffer.from( const basicCredential = Buffer.from(
`x-access-token:${this.settings.authToken}`, `x-access-token:${this.settings.authToken}`,

View file

@ -83,4 +83,10 @@ export interface IGitSourceSettings {
* Indicates whether to add repositoryPath as safe.directory in git global config * Indicates whether to add repositoryPath as safe.directory in git global config
*/ */
setSafeDirectory: boolean setSafeDirectory: boolean
/**
* Set a host to override the automatic detection. Useful when you need to clone
* from cloud when running an action on an on prem server
*/
setHost: string | undefined
} }

View file

@ -1,6 +1,7 @@
import * as assert from 'assert' import * as assert from 'assert'
import {IGitSourceSettings} from './git-source-settings' import {IGitSourceSettings} from './git-source-settings'
import {URL} from 'url' import {URL} from 'url'
import { settings } from 'cluster'
export function getFetchUrl(settings: IGitSourceSettings): string { export function getFetchUrl(settings: IGitSourceSettings): string {
assert.ok( assert.ok(
@ -8,7 +9,7 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
'settings.repositoryOwner must be defined' 'settings.repositoryOwner must be defined'
) )
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined') assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
const serviceUrl = getServerUrl() const serviceUrl = getServerUrl(settings.setHost)
const encodedOwner = encodeURIComponent(settings.repositoryOwner) const encodedOwner = encodeURIComponent(settings.repositoryOwner)
const encodedName = encodeURIComponent(settings.repositoryName) const encodedName = encodeURIComponent(settings.repositoryName)
if (settings.sshKey) { if (settings.sshKey) {
@ -19,7 +20,10 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}` return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
} }
export function getServerUrl(): URL { export function getServerUrl(configHost: string|undefined = undefined): URL {
if (configHost) {
return new URL(configHost)
}
// todo: remove GITHUB_URL after support for GHES Alpha is no longer needed // todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
return new URL( return new URL(
process.env['GITHUB_SERVER_URL'] || process.env['GITHUB_SERVER_URL'] ||