From 9d64c62a2e282f9f9f084f39e98b50eb46a35f56 Mon Sep 17 00:00:00 2001 From: Mark Wylde Date: Fri, 30 May 2025 20:32:40 +0100 Subject: [PATCH] Attempt to make this work --- src/github/operations/branch.ts | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index d973e53..129e412 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -113,18 +113,33 @@ export async function setupBranch( repo, branch: sourceBranch, }); - currentSHA = branchResponse.data.commit.sha; + // Gitea uses commit.id instead of commit.sha + currentSHA = branchResponse.data.commit.sha || branchResponse.data.commit.id; } console.log(`Current SHA: ${currentSHA}`); - // Create branch using GitHub API - await octokits.rest.git.createRef({ - owner, - repo, - ref: `refs/heads/${newBranch}`, - sha: currentSHA, - }); + // Create branch - try GitHub API first, fallback to Gitea API + try { + await octokits.rest.git.createRef({ + owner, + repo, + ref: `refs/heads/${newBranch}`, + sha: currentSHA, + }); + } catch (createRefError: any) { + // If git/refs creation fails (like in Gitea), use the branches endpoint + console.log(`git createRef failed, trying branches endpoint: ${createRefError.message}`); + + // Use Gitea's branch creation endpoint + const response = await octokits.request('POST /repos/{owner}/{repo}/branches', { + owner, + repo, + new_branch_name: newBranch, + old_branch_name: sourceBranch, + }); + console.log(`Created branch via branches endpoint: ${response.status}`); + } // Checkout the new branch (shallow fetch for performance) await $`git fetch origin --depth=1 ${newBranch}`;