From 410b0e84573f85018aef58c083cf5457d069c9dc Mon Sep 17 00:00:00 2001 From: volcano303 <75143900+volcano303@users.noreply.github.com> Date: Tue, 12 May 2026 19:34:32 +0200 Subject: [PATCH] fix(webhook): sync repo default branch from webhook payloads --- .../das/src/webhook/handlers/issue.handler.ts | 10 +++++++-- .../webhook/handlers/pull-request.handler.ts | 10 +++++++-- packages/das/src/webhook/webhook.service.ts | 21 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/packages/das/src/webhook/handlers/issue.handler.ts b/packages/das/src/webhook/handlers/issue.handler.ts index a94edbc..214719c 100644 --- a/packages/das/src/webhook/handlers/issue.handler.ts +++ b/packages/das/src/webhook/handlers/issue.handler.ts @@ -50,8 +50,14 @@ export class IssueHandler { await this.issueRepo.upsert(data, ["repoFullName", "issueNumber"]); - await this.repoRepo.update(repoFullName, { + const repoUpdate: Partial = { lastEventAt: new Date().toISOString(), - }); + }; + const defaultBranch: string | null = + payload.repository?.default_branch ?? null; + if (defaultBranch) { + repoUpdate.defaultBranch = defaultBranch; + } + await this.repoRepo.update(repoFullName, repoUpdate); } } diff --git a/packages/das/src/webhook/handlers/pull-request.handler.ts b/packages/das/src/webhook/handlers/pull-request.handler.ts index 7213834..bd70e83 100644 --- a/packages/das/src/webhook/handlers/pull-request.handler.ts +++ b/packages/das/src/webhook/handlers/pull-request.handler.ts @@ -53,9 +53,15 @@ export class PullRequestHandler { await this.prRepo.upsert(data, ["repoFullName", "prNumber"]); - await this.repoRepo.update(repoFullName, { + const repoUpdate: Partial = { lastEventAt: new Date().toISOString(), - }); + }; + const defaultBranch: string | null = + payload.repository?.default_branch ?? null; + if (defaultBranch) { + repoUpdate.defaultBranch = defaultBranch; + } + await this.repoRepo.update(repoFullName, repoUpdate); // Enqueue metadata fetch (closing issues + body + lastEditedAt) on relevant actions. // Also run on `edited` so post-merge body edits are captured. diff --git a/packages/das/src/webhook/webhook.service.ts b/packages/das/src/webhook/webhook.service.ts index ab4d707..aafa29d 100644 --- a/packages/das/src/webhook/webhook.service.ts +++ b/packages/das/src/webhook/webhook.service.ts @@ -91,6 +91,9 @@ export class WebhookService { } switch (event) { + case "repository": + await this.handleRepositoryEvent(payload); + break; case "pull_request": await this.pullRequestHandler.handle(payload); if (payload.action === "labeled" || payload.action === "unlabeled") { @@ -119,4 +122,22 @@ export class WebhookService { this.logger.debug(`Unhandled event type: ${event}`); } } + + private async handleRepositoryEvent( + payload: Record, + ): Promise { + const repoFullName: string | undefined = payload.repository?.full_name; + if (!repoFullName) return; + + const repoUpdate: Partial = { + lastEventAt: new Date().toISOString(), + }; + const defaultBranch: string | null = + payload.repository?.default_branch ?? null; + if (defaultBranch) { + repoUpdate.defaultBranch = defaultBranch; + } + + await this.repoRepo.update(repoFullName, repoUpdate); + } }