Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions packages/das/src/webhook/github-fetcher.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 ?? {};

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading