Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/api/routers/webhooks/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { logger } from '../../../utils/logging.js';
import { parseRepoFullName } from '../../../utils/repo.js';
import type { GitHubWebhook, ProjectContext } from './types.js';

const GITHUB_WEBHOOK_EVENTS = [
export const GITHUB_WEBHOOK_EVENTS = [
'pull_request',
'pull_request_review',
'pull_request_review_comment',
'check_suite',
'issue_comment',
];
Expand Down
2 changes: 1 addition & 1 deletion src/router/adapters/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ async function postGitHubPRAck(
return undefined;
}

const PROCESSABLE_EVENTS = [
export const PROCESSABLE_EVENTS = [
'pull_request',
'pull_request_review',
'pull_request_review_comment',
Expand Down
44 changes: 44 additions & 0 deletions tests/unit/integrations/github-webhook-events.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* GitHub webhook event-list consistency guard.
*
* The router processes events enumerated in `PROCESSABLE_EVENTS`
* (`src/router/adapters/github.ts`). For CASCADE to receive those events from
* GitHub, every processable event type must also appear in the
* `GITHUB_WEBHOOK_EVENTS` array used when programmatically creating webhooks
* (`src/api/routers/webhooks/github.ts`).
*
* This test prevents drift between the two lists. If a new event type is
* added to `PROCESSABLE_EVENTS` but forgotten in `GITHUB_WEBHOOK_EVENTS`,
* GitHub will never send that event payload to CASCADE — the trigger will
* silently never fire, which is the root cause this guard catches.
*
* Root-cause example: `pull_request_review_comment` was processed by
* `PRCommentMentionTrigger` but missing from the webhook creation list, so
* inline review comments were silently ignored.
*/

import { describe, expect, it } from 'vitest';
import { GITHUB_WEBHOOK_EVENTS } from '../../../src/api/routers/webhooks/github.js';
import { PROCESSABLE_EVENTS } from '../../../src/router/adapters/github.js';

describe('GitHub webhook event-list consistency', () => {
it('GITHUB_WEBHOOK_EVENTS contains every event in PROCESSABLE_EVENTS', () => {
const missing = PROCESSABLE_EVENTS.filter((event) => !GITHUB_WEBHOOK_EVENTS.includes(event));

expect(
missing,
`GITHUB_WEBHOOK_EVENTS is missing event(s) that are in PROCESSABLE_EVENTS: ${missing.join(', ')}. ` +
`GitHub will never deliver these events to CASCADE unless they are included in the ` +
`webhook creation payload. Add the missing events to GITHUB_WEBHOOK_EVENTS in ` +
`src/api/routers/webhooks/github.ts.`,
).toEqual([]);
});

it('GITHUB_WEBHOOK_EVENTS is a non-empty array', () => {
expect(GITHUB_WEBHOOK_EVENTS.length).toBeGreaterThan(0);
});

it('PROCESSABLE_EVENTS is a non-empty array', () => {
expect(PROCESSABLE_EVENTS.length).toBeGreaterThan(0);
});
});
8 changes: 1 addition & 7 deletions tools/setup-webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,11 @@
*/

import { Octokit } from '@octokit/rest';
import { GITHUB_WEBHOOK_EVENTS } from '../src/api/routers/webhooks/github.js';
import { closeDb } from '../src/db/client.js';
import { findProjectByIdFromDb } from '../src/db/repositories/configRepository.js';
import { resolveAllProjectCredentials } from '../src/db/repositories/credentialsRepository.js';

const GITHUB_WEBHOOK_EVENTS = [
'pull_request',
'pull_request_review',
'check_suite',
'issue_comment',
];

interface TrelloWebhook {
id: string;
description: string;
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/projects/integration-scm-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function GitHubWebhookSection({ projectId }: { projectId: string }) {
" -d '{",
' "name": "web",',
' "active": true,',
' "events": ["push", "pull_request", "check_suite", "pull_request_review"],',
' "events": ["push", "pull_request", "pull_request_review", "pull_request_review_comment", "check_suite", "issue_comment"],',
' "config": {',
` "url": "${webhookCallbackUrl}",`,
' "content_type": "json"',
Expand Down
Loading