mirror of
https://gitea.com/actions/checkout.git
synced 2024-11-15 00:09:27 +08:00
25 lines
848 B
TypeScript
25 lines
848 B
TypeScript
|
import * as assert from 'assert'
|
||
|
import {IGitSourceSettings} from './git-source-settings'
|
||
|
import {URL} from 'url'
|
||
|
|
||
|
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')
|
||
|
}
|