From 828076e41100db091c444c2d41f6892ef25ecde4 Mon Sep 17 00:00:00 2001 From: Mark Wylde Date: Fri, 30 May 2025 20:29:15 +0100 Subject: [PATCH] Attempt to make this work --- src/github/operations/branch.ts | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index 9bfd49c..d973e53 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -94,14 +94,27 @@ export async function setupBranch( try { // Get the SHA of the source branch - // For Gitea, use heads/ prefix like GitHub - const sourceBranchRef = await octokits.rest.git.getRef({ - owner, - repo, - ref: `heads/${sourceBranch}`, - }); - - const currentSHA = sourceBranchRef.data.object.sha; + // For Gitea, try using the branches endpoint instead of git/refs + let currentSHA: string; + + try { + // First try the GitHub-compatible git.getRef approach + const sourceBranchRef = await octokits.rest.git.getRef({ + owner, + repo, + ref: `heads/${sourceBranch}`, + }); + currentSHA = sourceBranchRef.data.object.sha; + } catch (gitRefError: any) { + // If git/refs fails (like in Gitea), use the branches endpoint + console.log(`git/refs failed, trying branches endpoint: ${gitRefError.message}`); + const branchResponse = await octokits.rest.repos.getBranch({ + owner, + repo, + branch: sourceBranch, + }); + currentSHA = branchResponse.data.commit.sha; + } console.log(`Current SHA: ${currentSHA}`);