mirror of
				https://github.com/actions/checkout.git
				synced 2025-11-03 23:20:54 +00:00 
			
		
		
		
	fix: octokit to use the correct enterprise url
This commit is contained in:
		
					parent
					
						
							
								2541b1294d
							
						
					
				
			
			
				commit
				
					
						aa195b11df
					
				
			
		
					 2 changed files with 22 additions and 4 deletions
				
			
		| 
						 | 
					@ -8,6 +8,7 @@ import * as retryHelper from './retry-helper'
 | 
				
			||||||
import * as toolCache from '@actions/tool-cache'
 | 
					import * as toolCache from '@actions/tool-cache'
 | 
				
			||||||
import {default as uuid} from 'uuid/v4'
 | 
					import {default as uuid} from 'uuid/v4'
 | 
				
			||||||
import {Octokit} from '@octokit/rest'
 | 
					import {Octokit} from '@octokit/rest'
 | 
				
			||||||
 | 
					import { getAPIUrl } from './url-helper'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const IS_WINDOWS = process.platform === 'win32'
 | 
					const IS_WINDOWS = process.platform === 'win32'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,7 +84,9 @@ export async function getDefaultBranch(
 | 
				
			||||||
): Promise<string> {
 | 
					): Promise<string> {
 | 
				
			||||||
  return await retryHelper.execute(async () => {
 | 
					  return await retryHelper.execute(async () => {
 | 
				
			||||||
    core.info('Retrieving the default branch name')
 | 
					    core.info('Retrieving the default branch name')
 | 
				
			||||||
    const octokit = new github.GitHub(authToken)
 | 
					    const octokit = new github.GitHub(authToken, {
 | 
				
			||||||
 | 
					      baseUrl: getAPIUrl()
 | 
				
			||||||
 | 
					    })
 | 
				
			||||||
    let result: string
 | 
					    let result: string
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      // Get the default branch from the repo info
 | 
					      // Get the default branch from the repo info
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,11 +19,26 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
 | 
				
			||||||
  return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
 | 
					  return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function getServerUrl(): URL {
 | 
					function getServerUrlFromEnv(): string | undefined {
 | 
				
			||||||
  // todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
 | 
					  // todo: remove GITHUB_URL after support for GHES Alpha is no longer needed
 | 
				
			||||||
 | 
					  return process.env['GITHUB_SERVER_URL'] ||
 | 
				
			||||||
 | 
					    process.env['GITHUB_URL']
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getServerUrl(): URL {
 | 
				
			||||||
  return new URL(
 | 
					  return new URL(
 | 
				
			||||||
    process.env['GITHUB_SERVER_URL'] ||
 | 
					    getServerUrlFromEnv() ||
 | 
				
			||||||
      process.env['GITHUB_URL'] ||
 | 
					 | 
				
			||||||
      'https://github.com'
 | 
					      'https://github.com'
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export function getAPIUrl(): URL {
 | 
				
			||||||
 | 
					  const urlFromEnv = getServerUrlFromEnv()
 | 
				
			||||||
 | 
					  if (urlFromEnv) {
 | 
				
			||||||
 | 
					    return new URL(`${urlFromEnv}/api/v3`)
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  return new URL(
 | 
				
			||||||
 | 
					    'https://api.github.com'
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue