From 8aabf05e48b6950a4ccd09b171096124a7654d20 Mon Sep 17 00:00:00 2001 From: eric sciple Date: Wed, 17 Jun 2020 17:44:27 -0400 Subject: [PATCH] fix default branch for .wiki --- dist/index.js | 21 ++++++++++++++++----- src/github-api-helper.ts | 23 ++++++++++++++++------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/dist/index.js b/dist/index.js index 4ade91c..36c0105 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9583,14 +9583,25 @@ function getDefaultBranch(authToken, owner, repo) { return yield retryHelper.execute(() => __awaiter(this, void 0, void 0, function* () { core.info('Retrieving the default branch name'); const octokit = new github.GitHub(authToken); - const response = yield octokit.repos.get({ owner, repo }); - if (response.status != 200) { - throw new Error(`Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}`); + let result; + try { + // 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 - let result = response.data.default_branch; core.info(`Default branch '${result}'`); - assert.ok(result, 'default_branch cannot be empty'); // Prefix with 'refs/heads' if (!result.startsWith('refs/')) { result = `refs/heads/${result}`; diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts index 7a09638..15ac77e 100644 --- a/src/github-api-helper.ts +++ b/src/github-api-helper.ts @@ -8,6 +8,7 @@ import * as retryHelper from './retry-helper' import * as toolCache from '@actions/tool-cache' import {default as uuid} from 'uuid/v4' import {Octokit} from '@octokit/rest' +import {Console} from 'console' const IS_WINDOWS = process.platform === 'win32' @@ -78,17 +79,25 @@ export async function getDefaultBranch( return await retryHelper.execute(async () => { core.info('Retrieving the default branch name') const octokit = new github.GitHub(authToken) - const response = await octokit.repos.get({owner, repo}) - if (response.status != 200) { - throw new Error( - `Unexpected response from GitHub API. Status: ${response.status}, Data: ${response.data}` - ) + let result: string + try { + // Get the default branch from the repo info + 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 - let result = response.data.default_branch core.info(`Default branch '${result}'`) - assert.ok(result, 'default_branch cannot be empty') // Prefix with 'refs/heads' if (!result.startsWith('refs/')) {