Skip to content

Commit 36d2166

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 6bacf42 commit 36d2166

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
@@ -457,6 +457,37 @@ it.effect("asks Forgejo for one required label by id and the author by login", (
457457
);
458458
});
459459

460+
it.effect("lists nothing for an author Forgejo has no account for", () =>
461+
Effect.gen(function* () {
462+
const provider = yield* ForgejoPullRequestProvider.make;
463+
const page = yield* provider.listChangeRequests({
464+
cwd: "/repo",
465+
repository: "maria/project",
466+
host: "forgejo.test",
467+
state: "open",
468+
involvement: "all",
469+
viewer: "maria",
470+
limit: 10,
471+
filters: { author: "nobody" },
472+
});
473+
assert.deepStrictEqual(page, { items: [], truncated: false, continues: false });
474+
}).pipe(
475+
Effect.provide(
476+
Layer.mock(ForgejoCli.ForgejoCli)({
477+
api: (input) =>
478+
Effect.fail(
479+
new ForgejoCli.ForgejoCliError({
480+
command: "fj",
481+
cwd: input.cwd,
482+
httpStatus: 400,
483+
detail: "Forgejo API request failed (HTTP 400): Poster not found",
484+
}),
485+
),
486+
}),
487+
),
488+
),
489+
);
490+
460491
it.effect("gives Forgejo identities the browser URL of the login that serves them", () =>
461492
Effect.gen(function* () {
462493
const provider = yield* ForgejoSourceControlProvider.make;

0 commit comments

Comments
 (0)