GitHub Webhooks
Complete reference for how CodeSpar receives and processes GitHub webhook events — supported event types, payload mapping to CIEvent, agent triggering behavior, auto-configuration, and testing.
GitHub Webhooks
CodeSpar receives GitHub webhook events to trigger automated agent responses. When a repository is linked, CodeSpar can auto-configure the webhook on GitHub (if WEBHOOK_BASE_URL and GITHUB_TOKEN are set) or you can configure it manually.
Webhook Endpoint
This is the single endpoint that receives all GitHub webhook events. CodeSpar inspects the X-GitHub-Event header to determine the event type, processes the payload, maps it to an internal CIEvent, and routes it to the appropriate agent.
Webhook URL Format
For example, if WEBHOOK_BASE_URL=https://codespar.example.com:
Supported Events
CodeSpar processes four GitHub event types and ignores the rest:
| GitHub Event | GitHub Action / Trigger | CodeSpar Behavior |
|---|---|---|
workflow_run | CI/CD workflow completes | Maps to CIEvent, triggers Incident Agent on failure |
pull_request | PR opened, updated, closed, merged | Maps to CIEvent, triggers Review Agent on open |
push | Code pushed to branch | Maps to CIEvent, updates project context |
check_run | Check suite completes | Maps to CIEvent, supplements workflow run data |
The CIEvent Type
All incoming GitHub webhook payloads are normalized into a common CIEvent type before being processed by agents:
How Events Map to CIEvent
workflow_run Event
Maps to:
pull_request Event
Maps to:
push Event
Maps to:
check_run Event
Maps to:
What Triggers Each Agent
When a CIEvent is created, the Project Agent evaluates it against the current autonomy level and decides whether to spawn an ephemeral agent.
Build Failure → Incident Agent
When a workflow_run event has conclusion: "failure":
| Autonomy Level | Behavior |
|---|---|
| L0 | Ignored |
| L1 | Notification sent: "Build failed on main" |
| L2 | Notification + suggestion: "I can investigate this failure. Approve?" |
| L3+ | Incident Agent spawned automatically — fetches workflow logs, analyzes the failure, identifies root cause, and reports findings to connected channels |
PR Opened → Review Agent
When a pull_request event has status: "opened":
| Autonomy Level | Behavior |
|---|---|
| L0 | Ignored |
| L1 | Notification: "New PR #42 opened by @alice" |
| L2 | Notification + suggestion: "I can review this PR. Approve?" |
| L3+ | Review Agent spawned automatically — reads the PR diff, analyzes code quality, checks for bugs, and posts a review comment on GitHub and in connected channels |
PR Merged → Notification
When a pull_request event has status: "closed" and merged: true:
| Autonomy Level | Behavior |
|---|---|
| L0 | Ignored |
| L1+ | Notification: "PR #42 merged into main by @alice" |
No agent is spawned for merge events — they are informational only.
Push → Context Update
When a push event is received:
| Autonomy Level | Behavior |
|---|---|
| L0 | Ignored |
| L1+ | Notification: "Push to main by @alice: feat: add rate limiting" |
| L3+ | Project context (vector store) is updated with the new commit information |
Auto-Webhook Configuration
When you link a repository via @codespar link or the Project API, CodeSpar automatically creates a GitHub webhook if these conditions are met:
WEBHOOK_BASE_URLis set (e.g.,https://codespar.example.com)GITHUB_TOKENhasadmin:repo_hookpermission
The webhook is configured to send:
pusheventspull_requesteventsworkflow_runeventscheck_runevents
Auto-Configuration Flow
If the token lacks admin:repo_hook permission, the project is still linked but without a webhook. The user must configure the webhook manually.
Manual Configuration
If auto-configuration is not available (e.g., no admin permissions), configure the webhook manually in GitHub:
- Go to your repository on GitHub
- Navigate to Settings > Webhooks > Add webhook
- Set the following:
| Field | Value |
|---|---|
| Payload URL | https://your-codespar-instance.com/webhooks/github |
| Content type | application/json |
| Secret | (optional, not currently validated) |
| Events | Select: Pushes, Pull requests, Workflow runs, Check runs |
- Click Add webhook
Testing Webhooks
You can test the webhook endpoint by sending simulated events with curl.
Simulate a Push Event
Simulate a PR Open Event
Simulate a Build Failure
Simulate a Check Run
Expected Response
All webhook events return 200 OK with a processing confirmation:
Unrecognized events return 200 OK with processed: false:
Webhook Payload Processing Flow
Next Steps
- Link a Repository — Set up webhook auto-configuration
- Review PRs Guide — Auto-review setup with Review Agent
- Graduated Autonomy — Control what agents do automatically
- Configuration —
WEBHOOK_BASE_URLand related env vars