mirror of
				https://github.com/actions/checkout.git
				synced 2025-11-01 02:28:40 +08:00 
			
		
		
		
	fix default branch for .wiki
This commit is contained in:
		
							parent
							
								
									b4483adec3
								
							
						
					
					
						commit
						8aabf05e48
					
				
							
								
								
									
										21
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										21
									
								
								dist/index.js
									
									
									
									
										vendored
									
									
								
							|  | @ -9583,14 +9583,25 @@ function getDefaultBranch(authToken, owner, repo) { | ||||||
|         return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { |         return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { | ||||||
|             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); | ||||||
|             const response = yield octokit.repos.get({ owner, repo }); |             let result; | ||||||
|             if (response.status != 200) { |             try { | ||||||
|                 throw new Error(`Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}`); |                 // Get the default branch from the repo info
 | ||||||
|  |                 const response = yield octokit.repos.get({ owner, repo }); | ||||||
|  |                 result = response.data.default_branch; | ||||||
|  |                 assert.ok(result, 'default_branch cannot be empty'); | ||||||
|  |             } | ||||||
|  |             catch (err) { | ||||||
|  |                 // Handle .wiki repo
 | ||||||
|  |                 if (err['status'] === 404 && repo.toUpperCase().endsWith('.WIKI')) { | ||||||
|  |                     result = 'master'; | ||||||
|  |                 } | ||||||
|  |                 // Otherwise error
 | ||||||
|  |                 else { | ||||||
|  |                     throw err; | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
|             // Print the default branch
 |             // Print the default branch
 | ||||||
|             let result = response.data.default_branch; |  | ||||||
|             core.info(`Default branch '${result}'`); |             core.info(`Default branch '${result}'`); | ||||||
|             assert.ok(result, 'default_branch cannot be empty'); |  | ||||||
|             // Prefix with 'refs/heads'
 |             // Prefix with 'refs/heads'
 | ||||||
|             if (!result.startsWith('refs/')) { |             if (!result.startsWith('refs/')) { | ||||||
|                 result = `refs/heads/${result}`; |                 result = `refs/heads/${result}`; | ||||||
|  |  | ||||||
|  | @ -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 {Console} from 'console' | ||||||
| 
 | 
 | ||||||
| const IS_WINDOWS = process.platform === 'win32' | const IS_WINDOWS = process.platform === 'win32' | ||||||
| 
 | 
 | ||||||
|  | @ -78,17 +79,25 @@ export async function getDefaultBranch( | ||||||
|   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) | ||||||
|     const response = await octokit.repos.get({owner, repo}) |     let result: string | ||||||
|     if (response.status != 200) { |     try { | ||||||
|       throw new Error( |       // Get the default branch from the repo info
 | ||||||
|         `Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}` |       const response = await octokit.repos.get({owner, repo}) | ||||||
|       ) |       result = response.data.default_branch | ||||||
|  |       assert.ok(result, 'default_branch cannot be empty') | ||||||
|  |     } catch (err) { | ||||||
|  |       // Handle .wiki repo
 | ||||||
|  |       if (err['status'] === 404 && repo.toUpperCase().endsWith('.WIKI')) { | ||||||
|  |         result = 'master' | ||||||
|  |       } | ||||||
|  |       // Otherwise error
 | ||||||
|  |       else { | ||||||
|  |         throw err | ||||||
|  |       } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     // Print the default branch
 |     // Print the default branch
 | ||||||
|     let result = response.data.default_branch |  | ||||||
|     core.info(`Default branch '${result}'`) |     core.info(`Default branch '${result}'`) | ||||||
|     assert.ok(result, 'default_branch cannot be empty') |  | ||||||
| 
 | 
 | ||||||
|     // Prefix with 'refs/heads'
 |     // Prefix with 'refs/heads'
 | ||||||
|     if (!result.startsWith('refs/')) { |     if (!result.startsWith('refs/')) { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 eric sciple
						eric sciple