diff --git a/src/github/operations/branch.ts b/src/github/operations/branch.ts index 86197da..1492438 100644 --- a/src/github/operations/branch.ts +++ b/src/github/operations/branch.ts @@ -13,6 +13,7 @@ import type { GitHubPullRequest } from "../types"; import type { Octokits } from "../api/client"; import type { FetchDataResult } from "../data/fetcher"; import { generateBranchName } from "../../utils/branch-template"; +import { detectPlatform } from "../../platform/detector"; /** * Extracts the first label from GitHub data, or returns undefined if no labels exist @@ -204,14 +205,25 @@ export async function setupBranch( let sourceSHA: string | undefined; try { - // Get the SHA of the source branch to verify it exists - const sourceBranchRef = await octokits.rest.git.getRef({ - owner, - repo, - ref: `heads/${sourceBranch}`, - }); - - sourceSHA = sourceBranchRef.data.object.sha; + // Get the SHA of the source branch to verify it exists. + // Forgejo uses /git/refs (plural) not /git/ref (singular), so + // git.getRef() 404s. Use repos.getBranch() on Forgejo instead. + const platform = detectPlatform(); + if (platform === "forgejo") { + const branchResponse = await octokits.rest.repos.getBranch({ + owner, + repo, + branch: sourceBranch, + }); + sourceSHA = branchResponse.data.commit.sha; + } else { + const sourceBranchRef = await octokits.rest.git.getRef({ + owner, + repo, + ref: `heads/${sourceBranch}`, + }); + sourceSHA = sourceBranchRef.data.object.sha; + } console.log(`Source branch SHA: ${sourceSHA}`); // Extract first label from GitHub data