mirror of
https://github.com/actions/checkout.git
synced 2024-12-27 08:11:03 +08:00
1d96c772d1
Some checks failed
Build and Test / test-proxy (push) Failing after 2s
Build and Test / test-git-container (push) Failing after 7s
Build and Test / build (push) Failing after 27s
Build and Test / test-bypass-proxy (push) Failing after 36s
Check dist / check-dist (push) Successful in 54s
Licensed / Check licenses (push) Failing after 53s
Build and Test / test (ubuntu-latest) (push) Failing after 1m35s
Build and Test / test (macos-latest) (push) Has been cancelled
Build and Test / test (windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Failing after 5s
* Add a configurable SSH user * Update docs with param * Indentation of readme * formatting woes * Update src/url-helper.ts Co-authored-by: Josh Gross <joshmgross@github.com> * Update action.yml Co-authored-by: Josh Gross <joshmgross@github.com> * Update genfiles --------- Co-authored-by: Josh Gross <joshmgross@github.com>
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import * as assert from 'assert'
|
|
import {URL} from 'url'
|
|
import {IGitSourceSettings} from './git-source-settings'
|
|
|
|
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(settings.githubServerUrl)
|
|
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
|
|
const encodedName = encodeURIComponent(settings.repositoryName)
|
|
if (settings.sshKey) {
|
|
const user = settings.sshUser.length > 0 ? settings.sshUser : 'git'
|
|
return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
|
|
}
|
|
|
|
// "origin" is SCHEME://HOSTNAME[:PORT]
|
|
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
|
|
}
|
|
|
|
export function getServerUrl(url?: string): URL {
|
|
let urlValue =
|
|
url && url.trim().length > 0
|
|
? url
|
|
: process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
|
return new URL(urlValue)
|
|
}
|
|
|
|
export function getServerApiUrl(url?: string): string {
|
|
let apiUrl = 'https://api.github.com'
|
|
|
|
if (isGhes(url)) {
|
|
const serverUrl = getServerUrl(url)
|
|
apiUrl = new URL(`${serverUrl.origin}/api/v3`).toString()
|
|
}
|
|
|
|
return apiUrl
|
|
}
|
|
|
|
export function isGhes(url?: string): boolean {
|
|
const ghUrl = getServerUrl(url)
|
|
|
|
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
|
}
|