mirror of
https://github.com/actions/checkout.git
synced 2025-04-20 01:26:46 +00:00
changes to support ghes alpha release (#199)
This commit is contained in:
parent
574281d34c
commit
85b1f35505
5 changed files with 93 additions and 24 deletions
28
src/url-helper.ts
Normal file
28
src/url-helper.ts
Normal file
|
@ -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')
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue