Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix: query the Forgejo host for Forgejo PR and issue lists (#17486)

Harsh Kashyap203624848403
diff --git a/.pr/forgejo-git-items-host/index.html b/.pr/forgejo-git-items-host/index.html
new file mode 100644
index 0000000000..198175ce8b
--- /dev/null
+++ b/.pr/forgejo-git-items-host/index.html
@@ -0,0 +1,12 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="utf-8" />
+ <title>Forgejo PR/issue lists queried api.github.com - repro evidence</title>
+</head>
+<body>
+ <h1>Reproduction evidence</h1>
+ <p>Terminal runs of <code>__tests__/api/git-provider-items-service.test.ts</code>: failing twice on main (requests go to api.github.com), passing twice with the fix (requests go to codeberg.org/api/v1).</p>
+ <img src="terminal.png" alt="vitest runs failing before the fix and passing after it" style="max-width:100%" />
+</body>
+</html>
diff --git a/.pr/forgejo-git-items-host/terminal.png b/.pr/forgejo-git-items-host/terminal.png
new file mode 100644
index 0000000000..c9d871bbe6
Binary files /dev/null and b/.pr/forgejo-git-items-host/terminal.png differ
diff --git a/__tests__/api/git-provider-items-service.test.ts b/__tests__/api/git-provider-items-service.test.ts
new file mode 100644
index 0000000000..f63b1d7c67
--- /dev/null
+++ b/__tests__/api/git-provider-items-service.test.ts
@@ -0,0 +1,108 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import {
+ __resetActiveStoreForTests,
+ setActiveSelection,
+ setRegisteredBackends,
+} from "#/api/backend-registry/active-store";
+import type { Backend } from "#/api/backend-registry/types";
+import { GitProviderItemsService } from "#/api/git-provider-items-service";
+import { getFetchCall, mockJsonResponse } from "./cloud/fetch-test-utils";
+
+// A cloud backend keeps provider tokens server-side, so the service never
+// touches the local secrets store and the provider REST call is the only
+// fetch in play.
+const cloudBackend: Backend = {
+ id: "prod",
+ name: "Production",
+ host: "https://app.all-hands.dev",
+ apiKey: "bearer-token",
+ kind: "cloud",
+};
+
+const originalFetch = global.fetch;
+const fetchMock = vi.fn();
+
+beforeEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+ setRegisteredBackends([cloudBackend]);
+ setActiveSelection({ backendId: cloudBackend.id });
+ fetchMock.mockReset();
+ global.fetch = fetchMock as unknown as typeof fetch;
+});
+
+afterEach(() => {
+ window.localStorage.clear();
+ __resetActiveStoreForTests();
+ fetchMock.mockReset();
+ global.fetch = originalFetch;
+});
+
+describe("GitProviderItemsService", () => {
+ it("lists Forgejo pull requests from the Forgejo host, not api.github.com", async () => {
+ fetchMock.mockResolvedValueOnce(
+ mockJsonResponse([
+ {
+ id: 11,
+ number: 7,
+ title: "Fix the thing",
+ html_url: "https://codeberg.org/acme/widgets/pulls/7",
+ user: { login: "octocat" },
+ updated_at: "2026-09-01T10:00:00Z",
+ },
+ ]),
+ );
+
+ const items = await GitProviderItemsService.listPullRequests(
+ "acme/widgets",
+ "forgejo",
+ );
+
+ const [url] = getFetchCall(fetchMock);
+ expect(url.startsWith("https://codeberg.org/api/v1/")).toBe(true);
+ expect(url).toContain("/repos/acme/widgets/pulls");
+ expect(items).toEqual([
+ {
+ id: 11,
+ number: 7,
+ title: "Fix the thing",
+ url: "https://codeberg.org/acme/widgets/pulls/7",
+ authorLogin: "octocat",
+ updatedAt: "2026-09-01T10:00:00Z",
+ },
+ ]);
+ });
+
+ it("lists Forgejo issues from the Forgejo host and skips pull requests", async () => {
+ fetchMock.mockResolvedValueOnce(
+ mockJsonResponse([
+ {
+ id: 21,
+ number: 3,
+ title: "Real issue",
+ html_url: "https://codeberg.org/acme/widgets/issues/3",
+ user: { login: "octocat" },
+ updated_at: null,
+ },
+ {
+ id: 22,
+ number: 4,
+ title: "A PR returned by the issues endpoint",
+ html_url: "https://codeberg.org/acme/widgets/pulls/4",
+ pull_request: { merged: false },
+ },
+ ]),
+ );
+
+ const items = await GitProviderItemsService.listIssues(
+ "acme/widgets",
+ "forgejo",
+ );
+
+ const [url] = getFetchCall(fetchMock);
+ expect(url.startsWith("https://codeberg.org/api/v1/")).toBe(true);
+ expect(url).toContain("/repos/acme/widgets/issues");
+ expect(items).toHaveLength(1);
+ expect(items[0].title).toBe("Real issue");
+ });
+});
diff --git a/src/api/git-provider-items-service.ts b/src/api/git-provider-items-service.ts
index 9b98af6778..278ba51992 100644
--- a/src/api/git-provider-items-service.ts
+++ b/src/api/git-provider-items-service.ts
@@ -127,6 +127,34 @@ async function fetchGithubJson<T>(
return response.json() as Promise<T>;
}
+async function fetchForgejoJson<T>(
+ path: string,
+ token: string | null,
+): Promise<T> {
+ const headers: Record<string, string> = {
+ Accept: "application/json",
+ };
+ if (token) {
+ // Forgejo/Gitea accept the `token` scheme on every supported version;
+ // `Bearer` only landed in later releases.
+ headers.Authorization = `token ${token}`;
+ }
+
+ // The provider host's own REST API (`/api/v1`), not api.github.com:
+ // Forgejo speaks the Gitea API shape on the instance that hosts the repo.
+ // eslint-disable-next-line local/no-direct-agent-server-fetch
+ const response = await fetch(
+ `${getGitProviderBaseUrl("forgejo")}/api/v1${path}`,
+ {
+ headers,
+ },
+ );
+ if (!response.ok) {
+ throw new Error(`Forgejo API ${response.status}`);
+ }
+ return response.json() as Promise<T>;
+}
+
async function fetchGitlabJson<T>(
path: string,
token: string | null,
@@ -212,7 +240,28 @@ export class GitProviderItemsService {
}));
}
- if (provider !== "github" && provider !== "forgejo") {
+ if (provider === "forgejo") {
+ const [forgejoOwner, forgejoRepo] = repository.split("/");
+ if (!forgejoOwner || !forgejoRepo) {
+ return [];
+ }
+ const items = await fetchForgejoJson<GithubIssueOrPr[]>(
+ `/repos/${forgejoOwner}/${forgejoRepo}/pulls?state=open&limit=${LIST_LIMIT}`,
+ token,
+ );
+ return items.map((item) => ({
+ id: item.id,
+ number: item.number,
+ title: item.title,
+ url:
+ item.html_url ||
+ constructPullRequestUrl(item.number, provider, repository),
+ authorLogin: item.user?.login ?? null,
+ updatedAt: item.updated_at ?? null,
+ }));
+ }
+
+ if (provider !== "github") {
return [];
}
@@ -260,7 +309,31 @@ export class GitProviderItemsService {
}));
}
- if (provider !== "github" && provider !== "forgejo") {
+ if (provider === "forgejo") {
+ const [forgejoOwner, forgejoRepo] = repository.split("/");
+ if (!forgejoOwner || !forgejoRepo) {
+ return [];
+ }
+ const items = await fetchForgejoJson<GithubIssueOrPr[]>(
+ `/repos/${forgejoOwner}/${forgejoRepo}/issues?state=open&type=issues&limit=${LIST_LIMIT}`,
+ token,
+ );
+ // Forgejo's issues endpoint can still return pull requests.
+ return items
+ .filter((item) => !item.pull_request)
+ .map((item) => ({
+ id: item.id,
+ number: item.number,
+ title: item.title,
+ url:
+ item.html_url ||
+ constructIssueUrl(item.number, provider, repository),
+ authorLogin: item.user?.login ?? null,
+ updatedAt: item.updated_at ?? null,
+ }));
+ }
+
+ if (provider !== "github") {
return [];
}