mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-04-24 04:15:33 +00:00
utl-helper.ts
now leverages well-known environment variables.
This commit is contained in:
parent
eef61447b9
commit
e8e821983d
4 changed files with 29 additions and 30 deletions
|
@ -88,7 +88,7 @@ export async function getDefaultBranch(
|
|||
return await retryHelper.execute(async () => {
|
||||
core.info('Retrieving the default branch name')
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: getServerApiUrl(baseUrl)
|
||||
baseUrl: getServerApiUrl()
|
||||
})
|
||||
let result: string
|
||||
try {
|
||||
|
@ -131,7 +131,7 @@ async function downloadArchive(
|
|||
baseUrl?: string
|
||||
): Promise<Buffer> {
|
||||
const octokit = github.getOctokit(authToken, {
|
||||
baseUrl: getServerApiUrl(baseUrl)
|
||||
baseUrl: getServerApiUrl()
|
||||
})
|
||||
const download = IS_WINDOWS
|
||||
? octokit.rest.repos.downloadZipballArchive
|
||||
|
|
|
@ -192,7 +192,7 @@ export async function checkCommitInfo(
|
|||
): Promise<void> {
|
||||
try {
|
||||
// GHES?
|
||||
if (isGhes(baseUrl)) {
|
||||
if (isGhes()) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -249,7 +249,7 @@ export async function checkCommitInfo(
|
|||
`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`
|
||||
)
|
||||
const octokit = github.getOctokit(token, {
|
||||
baseUrl: getServerApiUrl(baseUrl),
|
||||
baseUrl: getServerApiUrl(),
|
||||
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
|
||||
'number'
|
||||
)};run_id=${
|
||||
|
|
|
@ -28,19 +28,19 @@ export function getServerUrl(url?: string): URL {
|
|||
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 getServerApiUrl(): string {
|
||||
return process.env['GITHUB_API_URL'] || 'https://api.github.com'
|
||||
}
|
||||
|
||||
export function isGhes(url?: string): boolean {
|
||||
const ghUrl = getServerUrl(url)
|
||||
export function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
)
|
||||
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
||||
const hostname = ghUrl.hostname.trimEnd().toUpperCase()
|
||||
const isGitHubHost = hostname === 'GITHUB.COM'
|
||||
const isGheHost = hostname.endsWith('.GHE.COM')
|
||||
const isLocalHost = hostname.endsWith('.LOCALHOST')
|
||||
|
||||
return !isGitHubHost && !isGheHost && !isLocalHost
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue