diff options
| author | Peter Murray <681306+peter-murray@users.noreply.github.com> | 2022-09-26 17:34:52 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-26 12:34:52 -0400 |
| commit | e33cfa574212e8722034156757f8383979e76cb9 (patch) | |
| tree | 0c9284b63ea98535c6a10b080a477136102a6856 /src/ref-helper.ts | |
| parent | fa9591092fd91f59e3dbebbb92da3e2787a0bc03 (diff) | |
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
Diffstat (limited to 'src/ref-helper.ts')
| -rw-r--r-- | src/ref-helper.ts | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/ref-helper.ts b/src/ref-helper.ts index 209f49d..ce875fc 100644 --- a/src/ref-helper.ts +++ b/src/ref-helper.ts @@ -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' -} |
