From 29a1032aa68e8396eb5127e35e186941f56298c2 Mon Sep 17 00:00:00 2001 From: Vlad Mocanu Date: Thu, 26 Feb 2026 21:19:53 +0200 Subject: [PATCH] fix: normalize Forgejo PR/issue state to uppercase Forgejo REST API returns state as lowercase ("closed"/"open") but branch.ts compares against GraphQL-style uppercase ("CLOSED"/"MERGED"). This caused @claude on closed/merged PRs to take the open-PR checkout path, failing with "fatal: invalid reference: refs/pull/N/head". Normalize state to uppercase in the Forgejo data fetcher, matching the existing pattern used for review state (line 153). Co-Authored-By: Claude Opus 4.6 --- src/forgejo/data/fetcher.ts | 4 ++-- test/forgejo-data-fetcher.test.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/forgejo/data/fetcher.ts b/src/forgejo/data/fetcher.ts index 158b397..3e0f891 100644 --- a/src/forgejo/data/fetcher.ts +++ b/src/forgejo/data/fetcher.ts @@ -300,7 +300,7 @@ export async function fetchForgejoData({ lastEditedAt: undefined, additions: pr.additions, deletions: pr.deletions, - state: pr.state, + state: pr.state.toUpperCase(), // Normalize to uppercase (Forgejo REST returns "closed"/"open", branch.ts expects "CLOSED"/"MERGED") labels: { nodes: (pr.labels ?? []).map((l) => ({ name: typeof l === "string" ? l : (l.name ?? ""), @@ -352,7 +352,7 @@ export async function fetchForgejoData({ createdAt: issue.created_at, updatedAt: issue.updated_at, lastEditedAt: undefined, - state: issue.state ?? "open", + state: (issue.state ?? "open").toUpperCase(), // Normalize to uppercase for consistency with GraphQL conventions labels: { nodes: (issue.labels ?? []).map((l) => ({ name: typeof l === "string" ? l : (l.name ?? ""), diff --git a/test/forgejo-data-fetcher.test.ts b/test/forgejo-data-fetcher.test.ts index 2f7649f..3f6330f 100644 --- a/test/forgejo-data-fetcher.test.ts +++ b/test/forgejo-data-fetcher.test.ts @@ -211,7 +211,7 @@ describe("fetchForgejoData", () => { expect(pr.lastEditedAt).toBeUndefined(); expect(pr.additions).toBe(42); expect(pr.deletions).toBe(15); - expect(pr.state).toBe("open"); + expect(pr.state).toBe("OPEN"); }); it("should map PR labels correctly", async () => { @@ -455,7 +455,7 @@ describe("fetchForgejoData", () => { expect(issue.createdAt).toBe("2024-01-10T08:00:00Z"); expect(issue.updatedAt).toBe("2024-01-14T09:00:00Z"); expect(issue.lastEditedAt).toBeUndefined(); - expect(issue.state).toBe("open"); + expect(issue.state).toBe("OPEN"); expect(issue.labels.nodes).toEqual([{ name: "bug" }]); });