determine default branch (#278)

This commit is contained in:
eric sciple 2020-06-16 13:41:01 -04:00 committed by GitHub
parent 453ee27fca
commit 00a3be8934
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 78 additions and 18 deletions

View file

@ -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,