diff options
| author | eric sciple <ericsciple@users.noreply.github.com> | 2020-06-16 13:41:01 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-16 13:41:01 -0400 |
| commit | 17570e7adbcebf582c615bdac7f07339940d90e3 (patch) | |
| tree | 0db6cfd9a09a1bc192bd7f4238f68a627fadd348 /src/github-api-helper.ts | |
| parent | 7edd89f0f18ec3de28305003df3cccc46e4c60c9 (diff) | |
determine default branch (#278)
Diffstat (limited to 'src/github-api-helper.ts')
| -rw-r--r-- | src/github-api-helper.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts index e559c45..7a09638 100644 --- a/src/github-api-helper.ts +++ b/src/github-api-helper.ts @@ -67,6 +67,38 @@ export async function downloadRepository( io.rmRF(extractPath) } +/** + * Looks up the default branch name + */ +export async function getDefaultBranch( + authToken: string, + owner: string, + repo: string +): Promise<string> { + 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}` + ) + } + + // 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}` + } + + return result + }) +} + async function downloadArchive( authToken: string, owner: string, |
