mirror of
https://github.com/actions/checkout.git
synced 2025-04-20 01:26:46 +00:00
Inject GitHub host to be able to clone from another GitHub instance (#922)
* Adding the ability to specify the GitHub Server URL and allowing for it to differ from the Actions workflow host * Adding tests for injecting the GitHub URL * Addressing code review comments for PR #922
This commit is contained in:
parent
2541b1294d
commit
e6d535c99c
13 changed files with 220 additions and 67 deletions
|
@ -1,7 +1,8 @@
|
|||
import {URL} from 'url'
|
||||
import {IGitCommandManager} from './git-command-manager'
|
||||
import * as core from '@actions/core'
|
||||
import * as github from '@actions/github'
|
||||
import {getOctokit} from './octokit-provider'
|
||||
import {isGhes} from './url-helper'
|
||||
|
||||
export const tagsRefSpec = '+refs/tags/*:refs/tags/*'
|
||||
|
||||
|
@ -183,11 +184,12 @@ export async function checkCommitInfo(
|
|||
repositoryOwner: string,
|
||||
repositoryName: string,
|
||||
ref: string,
|
||||
commit: string
|
||||
commit: string,
|
||||
baseUrl?: string
|
||||
): Promise<void> {
|
||||
try {
|
||||
// GHES?
|
||||
if (isGhes()) {
|
||||
if (isGhes(baseUrl)) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -243,7 +245,8 @@ export async function checkCommitInfo(
|
|||
core.debug(
|
||||
`Expected head sha ${expectedHeadSha}; actual head sha ${actualHeadSha}`
|
||||
)
|
||||
const octokit = new github.GitHub(token, {
|
||||
const octokit = getOctokit(token, {
|
||||
baseUrl: baseUrl,
|
||||
userAgent: `actions-checkout-tracepoint/1.0 (code=STALE_MERGE;owner=${repositoryOwner};repo=${repositoryName};pr=${fromPayload(
|
||||
'number'
|
||||
)};run_id=${
|
||||
|
@ -276,10 +279,3 @@ function select(obj: any, path: string): any {
|
|||
const key = path.substr(0, i)
|
||||
return select(obj[key], path.substr(i + 1))
|
||||
}
|
||||
|
||||
function isGhes(): boolean {
|
||||
const ghUrl = new URL(
|
||||
process.env['GITHUB_SERVER_URL'] || 'https://github.com'
|
||||
)
|
||||
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM'
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue