diff --git a/packages/das/src/webhook/github-fetcher.service.ts b/packages/das/src/webhook/github-fetcher.service.ts index 88ad900..aba15fe 100644 --- a/packages/das/src/webhook/github-fetcher.service.ts +++ b/packages/das/src/webhook/github-fetcher.service.ts @@ -145,6 +145,14 @@ export class GitHubFetcherService implements OnModuleInit { return 60_000; } + private assertNoGraphQLErrors(body: any, context: string): void { + if (!body?.errors) return; + + throw new Error( + `${context} GraphQL errors: ${JSON.stringify(body.errors)}`, + ); + } + // --- Authentication --- private createAppJwt(): string { @@ -306,7 +314,13 @@ export class GitHubFetcherService implements OnModuleInit { } const body: any = await res.json(); - const pr = body.data?.repository?.pullRequest ?? {}; + this.assertNoGraphQLErrors(body, "PR metadata fetch"); + + const pr = body.data?.repository?.pullRequest; + if (!pr) { + throw new Error(`GraphQL PR metadata fetch returned no PR data`); + } + const nodes = pr.closingIssuesReferences?.nodes ?? []; return { @@ -578,11 +592,7 @@ export class GitHubFetcherService implements OnModuleInit { } const body: any = await res.json(); - if (body.errors) { - throw new Error( - `GraphQL content fetch errors: ${JSON.stringify(body.errors)}`, - ); - } + this.assertNoGraphQLErrors(body, "Content fetch"); const repoData = body.data?.repository ?? {}; @@ -758,9 +768,13 @@ export class GitHubFetcherService implements OnModuleInit { } const body: any = await res.json(); + this.assertNoGraphQLErrors(body, "Backfill PR fetch"); + const repoData: any = body.data?.repository; const page: any = repoData?.pullRequests; - if (!page) break; + if (!page) { + throw new Error(`Backfill PR GraphQL returned no pullRequests page`); + } // defaultBranchRef is the same across every page — write once. if (!defaultBranchWritten) { @@ -938,8 +952,12 @@ export class GitHubFetcherService implements OnModuleInit { } const body: any = await res.json(); + this.assertNoGraphQLErrors(body, "Backfill issue fetch"); + const page: any = body.data?.repository?.issues; - if (!page) break; + if (!page) { + throw new Error(`Backfill issue GraphQL returned no issues page`); + } let shouldStop = false; for (const issue of page.nodes) {