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:
authorYashwanth Anantharaju <yaananth@users.noreply.github.com>2026-06-01 11:35:58 -0400
committerGitHub <noreply@github.com>2026-06-01 11:35:58 -0400
commiteb9dcad7e007cb96364b4e612799ce0ff736cb09 (patch)
tree2730243bfbc90a8bc802720dc13e2e7ce433e7f2 /src/github-api-helper.ts
parent45c7dc79a6c1ac19a6a0981f08146cb419b30891 (diff)
Fix checkout init for SHA-256 repositories (#2439)
* Fix checkout init for SHA-256 repositories * Remove unused object format result field
Diffstat (limited to 'src/github-api-helper.ts')
-rw-r--r--src/github-api-helper.ts52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/github-api-helper.ts b/src/github-api-helper.ts
index 1ff27c2..bef31e6 100644
--- a/src/github-api-helper.ts
+++ b/src/github-api-helper.ts
@@ -11,6 +11,11 @@ import {getServerApiUrl} from './url-helper'
const IS_WINDOWS = process.platform === 'win32'
+export interface RepositoryObjectFormatResult {
+ format: string
+ succeeded: boolean
+}
+
export async function downloadRepository(
authToken: string,
owner: string,
@@ -122,6 +127,53 @@ export async function getDefaultBranch(
})
}
+export async function tryGetRepositoryObjectFormat(
+ authToken: string,
+ owner: string,
+ repo: string,
+ baseUrl?: string,
+ commit?: string
+): Promise<RepositoryObjectFormatResult> {
+ const commitFormat = getObjectFormat(commit)
+ if (commitFormat) {
+ return {format: commitFormat, succeeded: true}
+ }
+
+ try {
+ const octokit = github.getOctokit(authToken, {
+ baseUrl: getServerApiUrl(baseUrl)
+ })
+ const response = await octokit.request(
+ 'GET /repos/{owner}/{repo}/hash-algorithm',
+ {owner, repo}
+ )
+ const hashAlgorithm = response.data.hash_algorithm
+ if (hashAlgorithm === 'sha256' || hashAlgorithm === 'sha1') {
+ return {format: hashAlgorithm, succeeded: true}
+ }
+
+ core.debug(
+ 'Unable to determine repository object format from hash-algorithm endpoint'
+ )
+ return {format: '', succeeded: false}
+ } catch (err) {
+ core.debug(
+ `Unable to determine repository object format from hash-algorithm endpoint: ${(err as any)?.message ?? err}`
+ )
+ return {format: '', succeeded: false}
+ }
+}
+
+function getObjectFormat(sha?: string): string {
+ if (/^[0-9a-fA-F]{64}$/.test(sha || '')) {
+ return 'sha256'
+ }
+ if (/^[0-9a-fA-F]{40}$/.test(sha || '')) {
+ return 'sha1'
+ }
+ return ''
+}
+
async function downloadArchive(
authToken: string,
owner: string,