Skip to content

Commit 084dbbe

Browse files
fix(github): one malformed pull request no longer fails a whole head lookup batch
PullRequestsByHead decoded every row with the generated schema, so one row GitHub answered with an unexpected field failed every lookup that shared its batched document. The provider now reads the rows undecoded and decodes each against the generated PullRequestNode, skipping one that does not decode, as the listings and search already do. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 50d1369 commit 084dbbe

2 files changed

Lines changed: 73 additions & 6 deletions

File tree

‎packages/source-control-github/src/server/GitHubSourceControlProvider.test.ts‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,45 @@ describe("GitHubSourceControlProvider change request lookups by head", () => {
415415
}).pipe(Effect.provide(layer));
416416
});
417417

418+
it.effect("skips a row that does not decode and keeps the rest of the batch", () => {
419+
const { layer, graphqlCalls } = harness({
420+
remotes,
421+
graphql: (lookup) => ({
422+
pullRequests: {
423+
nodes:
424+
lookup.head === "feature/a"
425+
? [{ ...node(8, "feature/a"), number: "eight" }, node(7, "feature/a")]
426+
: [node(9, "feature/b")],
427+
},
428+
}),
429+
});
430+
return Effect.gen(function* () {
431+
const gh = yield* GitHubSourceControlProvider.make;
432+
const lookup = (headSelector: string) =>
433+
gh.listChangeRequests({
434+
cwd: "/repo",
435+
headSelector,
436+
state: "all",
437+
limit: 100,
438+
context: githubContext("github.com"),
439+
});
440+
const both = yield* Effect.all([lookup("feature/a"), lookup("feature/b")], {
441+
concurrency: "unbounded",
442+
}).pipe(Effect.forkChild);
443+
yield* TestClock.adjust("500 millis");
444+
const [first, second] = yield* Fiber.join(both);
445+
assert.strictEqual(graphqlCalls.length, 1);
446+
assert.deepStrictEqual(
447+
first.map((pr) => pr.number),
448+
[7],
449+
);
450+
assert.deepStrictEqual(
451+
second.map((pr) => pr.number),
452+
[9],
453+
);
454+
}).pipe(Effect.provide(layer));
455+
});
456+
418457
it.effect("caps a background document at twenty-five heads", () => {
419458
const { layer, graphqlCalls } = harness({
420459
remotes,

‎packages/source-control-github/src/server/GitHubSourceControlProvider.ts‎

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import * as Data from "effect/Data";
33
import * as DateTime from "effect/DateTime";
44
import * as Effect from "effect/Effect";
55
import * as FileSystem from "effect/FileSystem";
6-
import { GraphQLClient, GraphQLClientError, GraphQLResolver } from "effect/graphql";
6+
import {
7+
GraphQL,
8+
GraphQLClient,
9+
GraphQLClientError,
10+
GraphQLGroup,
11+
GraphQLResolver,
12+
} from "effect/graphql";
713
import * as Option from "effect/Option";
814
import * as RequestResolver from "effect/RequestResolver";
915
import * as Result from "effect/Result";
@@ -58,11 +64,30 @@ import { readSourceControlHostSettings } from "@t3tools/source-control-core/clie
5864

5965
import * as GitHubClient from "../client/definition.ts";
6066
import {
61-
SourceControlProviderGraphQLGroup,
62-
type PullRequestNode,
63-
type PullRequestsByHead,
67+
PullRequestByNumber,
68+
PullRequestNode,
69+
PullRequestsByHead,
6470
} from "./sourceControlProvider.graphql.ts";
6571

72+
/**
73+
* The generated head lookup with its rows left undecoded, so `listByHead` decodes them one at a
74+
* time: a row whose fields no longer decode is skipped rather than failing every lookup that
75+
* shared its document.
76+
*/
77+
const LenientPullRequestsByHead = GraphQL.query(PullRequestsByHead.name, {
78+
// The template, not the joined text: `GraphQLResolver.aliased` repeats it per lookup.
79+
document: PullRequestsByHead.template!,
80+
variables: PullRequestsByHead.variables,
81+
result: Schema.Struct({
82+
repository: Schema.NullOr(
83+
Schema.Struct({
84+
pullRequests: Schema.Struct({ nodes: Schema.NullOr(Schema.Array(Schema.Unknown)) }),
85+
}),
86+
),
87+
}),
88+
});
89+
const decodePullRequestNode = Schema.decodeUnknownOption(PullRequestNode);
90+
6691
const decodeLinkSubject = Schema.decodeUnknownEffect(
6792
Schema.fromJsonString(
6893
Schema.Struct({ title: Schema.String, body: Schema.optional(Schema.NullOr(Schema.String)) }),
@@ -515,7 +540,9 @@ export const make = Effect.gen(function* () {
515540
);
516541

517542
const client = yield* GraphQLClient.make(
518-
SourceControlProviderGraphQLGroup.middleware(GitHubGraphQlClient.GitHubGraphQlAuth),
543+
GraphQLGroup.make(LenientPullRequestsByHead, PullRequestByNumber).middleware(
544+
GitHubGraphQlClient.GitHubGraphQlAuth,
545+
),
519546
).pipe(Effect.provide(GitHubGraphQlClient.layer));
520547

521548
/**
@@ -599,7 +626,8 @@ export const make = Effect.gen(function* () {
599626
),
600627
);
601628
if (result.repository === null) return yield* notFound("The repository could not be read.");
602-
const rows = (result.repository.pullRequests.nodes ?? []).flatMap((node) => {
629+
const rows = (result.repository.pullRequests.nodes ?? []).flatMap((entry) => {
630+
const node = Option.getOrNull(decodePullRequestNode(entry));
603631
const record = node === null ? null : toPullRequestRecord(node);
604632
return record === null ? [] : [record];
605633
});

0 commit comments

Comments
 (0)