Skip to content

Commit c7d24c3

Browse files
fix(forgejo): an author with no account lists nothing instead of failing
Forgejo answers a poster that names no account with HTTP 400, so filtering by such an author marked the whole repository unreadable. The first page's 400 on a poster listing now reads as an empty answer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent ddeb4a1 commit c7d24c3

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

‎packages/source-control-forgejo/src/server/ForgejoPullRequestProvider.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,18 @@ export const make = Effect.gen(function* () {
272272
const query = { ...input, path: `${repoPath(input)}/pulls?${params}` };
273273
// Self-hosted servers may cap pages below 50. Establish their actual page size before
274274
// translating the service's row offset into an API page number.
275-
const first = yield* readPage(query, Schema.NullOr(ForgejoPullRequest), 1);
275+
const first = yield* readPage(query, Schema.NullOr(ForgejoPullRequest), 1).pipe(
276+
Effect.catchTags({
277+
// Forgejo answers a `poster` naming no account with a 400: nobody to list for.
278+
PullRequestProviderError: (error) =>
279+
params.has("poster") &&
280+
isForgejoCliError(error.cause) &&
281+
error.cause.httpStatus === 400
282+
? Effect.succeed(null)
283+
: Effect.fail(error),
284+
}),
285+
);
286+
if (first === null) return { items: [], truncated: false, continues: false };
276287
const pageSize = first.rows.length || 50;
277288
const firstIndex = Math.floor(offset / pageSize) + 1;
278289
let consumed = 0;

‎packages/source-control-forgejo/src/server/ForgejoSourceControlProvider.test.ts‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,37 @@ it.effect("asks Forgejo for one required label by id and the author by login", (
523523
);
524524
});
525525

526+
it.effect("lists nothing for an author Forgejo has no account for", () =>
527+
Effect.gen(function* () {
528+
const provider = yield* ForgejoPullRequestProvider.make;
529+
const page = yield* provider.listChangeRequests({
530+
cwd: "/repo",
531+
repository: "maria/project",
532+
host: "forgejo.test",
533+
state: "open",
534+
involvement: "all",
535+
viewer: "maria",
536+
limit: 10,
537+
filters: { author: "nobody" },
538+
});
539+
assert.deepStrictEqual(page, { items: [], truncated: false, continues: false });
540+
}).pipe(
541+
Effect.provide(
542+
Layer.mock(ForgejoCli.ForgejoCli)({
543+
api: (input) =>
544+
Effect.fail(
545+
new ForgejoCli.ForgejoCliError({
546+
command: "fj",
547+
cwd: input.cwd,
548+
httpStatus: 400,
549+
detail: "Forgejo API request failed (HTTP 400): Poster not found",
550+
}),
551+
),
552+
}),
553+
),
554+
),
555+
);
556+
526557
it.effect("gives Forgejo identities the browser URL of the login that serves them", () =>
527558
Effect.gen(function* () {
528559
const provider = yield* ForgejoSourceControlProvider.make;

0 commit comments

Comments
 (0)