Repository navigation
Closed
Description
Goal:
Implement a GitHub webhook listener as an alternative to the current polling mechanism for detecting new issues and PR comments. This should be configurable via environment variables.
The webhook listener should run within the 'daemon' service, as it has access to the task queue and configuration.
Implementation Steps:
-
Update Dependencies:
- Add 'express' to the root 'package.json'.
- Run 'npm install'.
-
Refactor 'src/daemon.js' Logic:
- Create a new helper function 'processDetectedIssue' that takes an 'issue' object. This function will contain the logic currently in 'pollForIssues' for checking labels, finding target models, and enqueueing one or more 'processGitHubIssueJob' tasks.
- Create a new helper function 'processCommentEvent' that takes a 'payload' (from 'issue_comment' or 'pull_request_review_comment') and the 'eventType'. This function will contain the logic for checking authors, trigger keywords, and enqueueing a 'processPullRequestCommentJob'.
- Refactor 'pollForIssues' and 'pollForPullRequestComments' to use these new helper functions in their loops.
-
Add Webhook Server to 'src/daemon.js':
- Import 'express' and 'crypto'.
- Add new constants for 'ENABLE_WEBHOOKS', 'WEBHOOK_PORT', and 'WEBHOOK_SECRET' from 'process.env'.
- Create a 'verifySignature' middleware function that uses 'express.raw' and 'crypto.createHmac' to validate the 'X-Hub-Signature-256' header against the 'WEBHOOK_SECRET'.
- Create a 'setupWebhookServer' function that initializes an Express app.
- Add a 'POST /webhook' route to the app. This route MUST use the 'verifySignature' middleware first.
- The '/webhook' handler should:
- Read the 'x-github-event' header.
- Parse the JSON payload (from 'req.body').
- Use a 'switch' statement on the event type:
- 'case 'issues'': If 'action' is 'labeled', call 'processDetectedIssue(payload.issue)'.
- 'case 'issue_comment'': If 'action' is 'created', call 'processCommentEvent(payload, 'issue_comment')'.
- 'case 'pull_request_review_comment'': If 'action' is 'created', call 'processCommentEvent(payload, 'pull_request_review_comment')'.
- Start this server ('app.listen') inside 'setupWebhookServer'.
-
Update 'startDaemon' in 'src/daemon.js':
- At the beginning of the function, check 'if (ENABLE_WEBHOOKS)'.
- If 'true':
- Call 'await setupWebhookServer();'
- Log that the webhook listener is active on 'WEBHOOK_PORT'.
- DO NOT call 'safePoll()' or 'setInterval(safePoll, ...)'.
- If 'false':
- Keep the existing 'safePoll()' and 'setInterval' logic.
- IMPORTANT: The config reloading interval and heartbeats should run in both modes.
-
Update Config Files:
- '.env.example': Add 'ENABLE_GITHUB_WEBHOOKS=false' and 'WEBHOOK_PORT=9090'.
- 'docker-compose.yml': Expose the 'WEBHOOK_PORT' on the 'daemon' service.
- 'docker-compose.prod.yml': Expose the 'WEBHOOK_PORT' on the 'daemon' service.
By centralizing the enqueueing logic, both the poller and the new webhook handler can use the same functions, reducing code duplication.
Activity
integry commentedon Nov 14, 2025
Here are the implementation details:
1.
package.json(root):Add 'express' to dependencies:
"dependencies": { "@anthropic-ai/claude-code": "^2.0.1", "@octokit/auth-app": "^8.0.1", ... "bullmq": "^5.53.0", "dotenv": "^16.5.0", + "express": "^4.19.2", "fs-extra": "^11.3.0", ...2.
.env.example:Add new variables for webhook configuration.
3.
docker-compose.yml:Expose the webhook port on the 'daemon' service.
daemon: build: context: . dockerfile: Dockerfile.node container_name: gitfix-daemon command: npm run daemon + ports: + - "${WEBHOOK_PORT:-9090}:${WEBHOOK_PORT:-9090}" volumes: - ./logs:/usr/src/app/logs ...4.
docker-compose.prod.yml:Also expose the port in the production config.
daemon: build: context: . dockerfile: Dockerfile restart: unless-stopped + ports: + - "${WEBHOOK_PORT:-9090}:${WEBHOOK_PORT:-9090}" environment: NODE_ENV: production ...5.
src/daemon.js:This file will have the most significant changes.
Imports:
New Constants:
New Refactored Enqueueing Logic:
(Create these functions to be called by both polling and webhooks)
New Webhook Server Logic:
Updated 'startDaemon' Logic:
propr-dev commentedon Nov 14, 2025
🤖 AI processing has started for this issue using claude-sonnet-4-5-20250929 model.
I'll analyze the problem and work on a solution. This may take a few minutes.
Processing Details:
claude-sonnet-4-5-20250929ai-fix/237-feature-implement-github--20251114-1132-claude-sonnet-4-5-20250929-5lemainissue-237-20251114-1132-claude-sonnet-4-5-20250929-5lefix(ai): Resolve issue #237 - Feature: Implement GitHub Webhook Handl…
Merge pull request #239 from integry/ai-fix/237-feature-implement-git…