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); + } }