mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-04-21 17:12:03 +03:00
add support for gist.github.com
This commit is contained in:
parent
aabbfeb2ce
commit
ec00d65c65
9 changed files with 69 additions and 16 deletions
|
@ -51,7 +51,7 @@ class GitAuthHelper {
|
|||
this.settings = gitSourceSettings || (({} as unknown) as IGitSourceSettings)
|
||||
|
||||
// Token auth header
|
||||
const serverUrl = urlHelper.getServerUrl()
|
||||
const serverUrl = urlHelper.getServerUrl(this.settings.isGist)
|
||||
this.tokenConfigKey = `http.${serverUrl.origin}/.extraheader` // "origin" is SCHEME://HOSTNAME[:PORT]
|
||||
const basicCredential = Buffer.from(
|
||||
`x-access-token:${this.settings.authToken}`,
|
||||
|
|
|
@ -73,4 +73,9 @@ export interface IGitSourceSettings {
|
|||
* Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
|
||||
*/
|
||||
persistCredentials: boolean
|
||||
|
||||
/**
|
||||
* Indicates whether this repository is a gist
|
||||
*/
|
||||
isGist: boolean
|
||||
}
|
||||
|
|
|
@ -16,10 +16,17 @@ export function getInputs(): IGitSourceSettings {
|
|||
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`)
|
||||
fsHelper.directoryExistsSync(githubWorkspacePath, true)
|
||||
|
||||
// Gist repository?
|
||||
result.isGist = !!core.getInput('gist') || false
|
||||
core.debug(`isGist = '${result.isGist}'`)
|
||||
|
||||
// Qualified repository
|
||||
const qualifiedRepository =
|
||||
let qualifiedRepository =
|
||||
core.getInput('repository') ||
|
||||
`${github.context.repo.owner}/${github.context.repo.repo}`
|
||||
if (result.isGist) {
|
||||
qualifiedRepository = core.getInput('gist')
|
||||
}
|
||||
core.debug(`qualified repository = '${qualifiedRepository}'`)
|
||||
const splitRepository = qualifiedRepository.split('/')
|
||||
if (
|
||||
|
@ -27,8 +34,9 @@ export function getInputs(): IGitSourceSettings {
|
|||
!splitRepository[0] ||
|
||||
!splitRepository[1]
|
||||
) {
|
||||
const model = result.isGist ? 'gist' : 'repository'
|
||||
throw new Error(
|
||||
`Invalid repository '${qualifiedRepository}'. Expected format {owner}/{repo}.`
|
||||
`Invalid ${model} '${qualifiedRepository}'. Expected format {owner}/{repo}.`
|
||||
)
|
||||
}
|
||||
result.repositoryOwner = splitRepository[0]
|
||||
|
|
|
@ -8,22 +8,33 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
|
|||
'settings.repositoryOwner must be defined'
|
||||
)
|
||||
assert.ok(settings.repositoryName, 'settings.repositoryName must be defined')
|
||||
const serviceUrl = getServerUrl()
|
||||
const serviceUrl = getServerUrl(settings.isGist)
|
||||
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
|
||||
const encodedName = encodeURIComponent(settings.repositoryName)
|
||||
let encodedNwo = `${encodedOwner}/${encodedName}`
|
||||
if (settings.isGist) {
|
||||
encodedNwo = encodedName
|
||||
}
|
||||
if (settings.sshKey) {
|
||||
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
|
||||
return `git@${serviceUrl.hostname}:${encodedNwo}.git`
|
||||
}
|
||||
|
||||
// "origin" is SCHEME://HOSTNAME[:PORT]
|
||||
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
|
||||
return `${serviceUrl.origin}/${encodedNwo}`
|
||||
}
|
||||
|
||||
export function getServerUrl(): URL {
|
||||
export function getServerUrl(isGist: boolean): URL {
|
||||
// todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
|
||||
return new URL(
|
||||
let serverUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] ||
|
||||
process.env['GITHUB_URL'] ||
|
||||
'https://github.com'
|
||||
)
|
||||
|
||||
// todo: don't assume subdomain isolation
|
||||
if (isGist) {
|
||||
serverUrl.hostname = `gist.${serverUrl.hostname}`
|
||||
}
|
||||
|
||||
return serverUrl
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue