Skip to content

Webhook Worker

Receives and routes all incoming GitHub webhooks to the appropriate handler.

Architecture

Webhook routing uses a handler registry pattern. The main dispatcher (lib/webhookHandlers/index.js) maps event names to handler functions:

mermaid
graph TD
    WH["POST /webhooks/github"] --> SIG["Verify HMAC-SHA256"]
    SIG --> DISP["routeWebhookToQueue()"]
    DISP --> LOOKUP{"Handler registered?"}
    LOOKUP -->|Yes| H["Call handler(event, deliveryId, ctx)"]
    LOOKUP -->|No| GEN["Add to webhook queue (generic)"]
    H --> HI[handleIssues]
    H --> HPR[handlePullRequest]
    H --> HPRR[handlePullRequestReview]
    H --> HCS[handleCheckSuite]
    H --> HWR[handleWorkflowRun]
    H --> HINST[handleInstallation]
    H --> HP[handlePush]
    H --> HIC[handleIssueComment]
    HIC --> CMDS["Comment Commands"]
    CMDS --> CMD_RUN["/gitwire run"]
    CMDS --> CMD_FIX["/gitwire fix"]
    CMDS --> CMD_WAIVE["/gitwire waive"]

Handler Registry

EventHandler FileActions HandledRoutes To
issueshandleIssues.jsopened, reopened, editedtriage queue
pull_requesthandlePullRequest.jsopened, reopened, ready_for_review, synchronize, closedtriage queue, phase4 queue, reconciliation
pull_request_reviewhandlePullRequestReview.jssubmitted (approved only)merge queue (phase2)
check_suitehandleCheckSuite.jscompletedmerge queue check
workflow_runhandleWorkflowRun.jscompletedci-heal queue (failures), merge queue, rollback eval, test ingestion
installationhandleInstallation.jscreated, new_permissions_acceptedsync queue
installation_repositorieshandleInstallation.jsaddedsync queue
pushhandlePush.jsall pushesconfig cache invalidation, sync queue
issue_commenthandleIssueComment.jscreated (bot command)comment command sub-dispatcher

All other events are added to the webhook-events queue as generic events.

Comment Commands

issue_comment events containing /gitwire are parsed by commentRouter.js and dispatched to sub-handlers in commentCommands/:

CommandHandlerDescription
/gitwire run [pillar]handleManualRun.jsRe-evaluate one or more pillars for an issue/PR
/gitwire fixhandleFixCommand.jsTrigger autonomous issue fix pipeline
/gitwire waive [policy]handleWaiverCommand.jsGrant or revoke a policy waiver

Shared Context

All handlers receive a shared ctx object instead of importing queues directly:

javascript
const ctx = {
  webhookQueue, triageQueue, ciHealQueue, maintainerQueue,
  issueFixQueue, phase2Queue, phase3Queue, phase4Queue,
  redis, db, logger, getInstallationClient, wrapOctokit,
};

This keeps each handler file focused on event logic (CC ~3-8) without infrastructure imports.

Webhook Verification

Every webhook is verified using HMAC-SHA256 with the GITHUB_WEBHOOK_SECRET. Invalid signatures are rejected with 401.

Delivery Logging

All webhooks are logged in webhook_deliveries with:

  • Delivery ID, event name, action
  • Processing status (success/failed)
  • Error message if failed

Webhook Routing | Comment Commands | Triage Worker

Last validated: v0.13.0

Released under the MIT License.