mirror of
https://code.forgejo.org/actions/checkout.git
synced 2025-04-22 01:22:02 +03:00
determine default branch (#278)
This commit is contained in:
parent
453ee27fca
commit
00a3be8934
7 changed files with 78 additions and 18 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue