Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/github-api-helper.ts
diff options
context:
space:
mode:
authoreric sciple <ericsciple@users.noreply.github.com>2020-06-16 13:41:01 -0400
committerGitHub <noreply@github.com>2020-06-16 13:41:01 -0400
commit17570e7adbcebf582c615bdac7f07339940d90e3 (patch)
tree0db6cfd9a09a1bc192bd7f4238f68a627fadd348 /src/github-api-helper.ts
parent7edd89f0f18ec3de28305003df3cccc46e4c60c9 (diff)
determine default branch (#278)
Diffstat (limited to 'src/github-api-helper.ts')
-rw-r--r--src/github-api-helper.ts32
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,