From a8430d4114b91a5f4c78d8c26cecda2fe37d68b1 Mon Sep 17 00:00:00 2001 From: pttydou <207957031+pttydou@users.noreply.github.com> Date: Sun, 23 Aug 2026 11:19:10 +0800 Subject: [PATCH] fix(webhooks): ignore unhandled event types --- src/github/github-webhooks.service.spec.ts | 18 ++++++++++++++++++ src/github/github-webhooks.service.ts | 12 ++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/github/github-webhooks.service.spec.ts b/src/github/github-webhooks.service.spec.ts index fe5bb14..76ab565 100644 --- a/src/github/github-webhooks.service.spec.ts +++ b/src/github/github-webhooks.service.spec.ts @@ -83,6 +83,23 @@ describe('GithubWebhooksService', () => { expect(bountiesService.markMergedAndRelease).not.toHaveBeenCalled(); }); + it.each(['push', 'ping', 'unknown_event'])( + 'ignores a verified %s event when no handler is registered', + async (eventType) => { + const event = await service.handleEvent( + eventType, + 'delivery-unhandled', + {}, + true, + ); + + expect(event.status).toBe(WebhookEventStatus.IGNORED); + expect(event.processedAt).toBeUndefined(); + expect(syncService.findRepositoryByGithubId).not.toHaveBeenCalled(); + expect(bountiesService.markMergedAndRelease).not.toHaveBeenCalled(); + }, + ); + it('processes a merged pull_request event and releases the linked bounty', async () => { issueRepo.findOne.mockResolvedValue({ id: 'issue-1', @@ -279,6 +296,7 @@ describe('GithubWebhooksService', () => { payload.issue, ); expect(event.status).toBe(WebhookEventStatus.PROCESSED); + expect(event.processedAt).toBeInstanceOf(Date); }); it('ignores events for a repository this app is not tracking, without erroring', async () => { diff --git a/src/github/github-webhooks.service.ts b/src/github/github-webhooks.service.ts index ea950c6..4ca71da 100644 --- a/src/github/github-webhooks.service.ts +++ b/src/github/github-webhooks.service.ts @@ -99,14 +99,14 @@ export class GithubWebhooksService { payload as unknown as GithubPullRequestPayload, ); this.applyPullRequestOutcomes(event, outcomes); - } else { - if (eventType === 'issues') { - await this.handleIssueEvent( - payload as unknown as GithubIssuesEventPayload, - ); - } + } else if (eventType === 'issues') { + await this.handleIssueEvent( + payload as unknown as GithubIssuesEventPayload, + ); event.status = WebhookEventStatus.PROCESSED; event.processedAt = new Date(); + } else { + event.status = WebhookEventStatus.IGNORED; } } catch (err) { event.status = WebhookEventStatus.FAILED;