Attempt to make this work

This commit is contained in:
Mark Wylde
2025-05-30 20:32:40 +01:00
parent 828076e411
commit 9d64c62a2e

View File

@@ -113,18 +113,33 @@ export async function setupBranch(
repo, repo,
branch: sourceBranch, 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}`); console.log(`Current SHA: ${currentSHA}`);
// Create branch using GitHub API // Create branch - try GitHub API first, fallback to Gitea API
try {
await octokits.rest.git.createRef({ await octokits.rest.git.createRef({
owner, owner,
repo, repo,
ref: `refs/heads/${newBranch}`, ref: `refs/heads/${newBranch}`,
sha: currentSHA, 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) // Checkout the new branch (shallow fetch for performance)
await $`git fetch origin --depth=1 ${newBranch}`; await $`git fetch origin --depth=1 ${newBranch}`;