GitHub Integration
Fluxbase can automatically create and delete database branches when GitHub pull requests are opened, closed, or merged.
Overview
Section titled “Overview”When integrated with GitHub:
- PR Opened/Reopened - Creates a database branch named
pr-{number} - PR Closed/Merged - Deletes the associated branch
This enables isolated preview environments for each pull request.
1. Configure Repository
Section titled “1. Configure Repository”Register your GitHub repository with Fluxbase:
curl -X POST http://localhost:8080/api/v1/admin/branches/github/configs \ -H "Authorization: Bearer $SERVICE_KEY" \ -H "Content-Type: application/json" \ -d '{ "repository": "owner/repo-name", "webhook_secret": "your-secure-secret", "auto_create_on_pr": true, "auto_delete_on_merge": true, "default_data_clone_mode": "schema_only" }'2. Add Webhook in GitHub
Section titled “2. Add Webhook in GitHub”- Go to your repository Settings > Webhooks
- Click Add webhook
- Configure:
- Payload URL:
https://your-fluxbase-server.com/api/v1/webhooks/github - Content type:
application/json - Secret: Same as
webhook_secretabove - Events: Select “Pull requests”
- Payload URL:
- Click Add webhook
3. Verify Setup
Section titled “3. Verify Setup”Create a test PR and check the Fluxbase logs:
fluxbase branch listYou should see a new branch named pr-{number}.
Configuration Options
Section titled “Configuration Options”| Field | Type | Default | Description |
|---|---|---|---|
repository | string | Required | GitHub repository (owner/repo) |
webhook_secret | string | - | Webhook signature secret |
auto_create_on_pr | bool | true | Create branch on PR open |
auto_delete_on_merge | bool | true | Delete branch on PR close |
default_data_clone_mode | string | schema_only | Clone mode for PR branches |
Webhook Security
Section titled “Webhook Security”Signature Verification
Section titled “Signature Verification”GitHub signs webhook payloads with HMAC-SHA256. Fluxbase verifies signatures when webhook_secret is configured.
Behavior:
| Secret Configured | Signature Sent | Result |
|---|---|---|
| Yes | Yes (valid) | Accepted |
| Yes | Yes (invalid) | Rejected |
| Yes | No | Rejected |
| No | Yes | Accepted (with warning) |
| No | No | Rejected* |
*Unconfigured repositories are rejected to prevent abuse. Configure the repository first.
Best Practices
Section titled “Best Practices”- Always configure a webhook secret - Use a strong, random secret
- Use HTTPS - Never send webhooks over plain HTTP
- Rotate secrets periodically - Update both GitHub and Fluxbase config
Generate a secure secret:
openssl rand -hex 32Webhook Events
Section titled “Webhook Events”Handled Events
Section titled “Handled Events”| Event | Action | Result |
|---|---|---|
pull_request | opened | Create branch pr-{number} |
pull_request | reopened | Create branch if not exists |
pull_request | closed | Delete branch |
pull_request | synchronize | (Acknowledged, no action) |
ping | - | Returns “pong” |
Ignored Events
Section titled “Ignored Events”All other events are acknowledged but ignored.
Branch Naming
Section titled “Branch Naming”PR branches are automatically named:
- Name:
PR #{number} - Slug:
pr-{number} - Database:
branch_pr_{number}
Example for PR #42:
- Slug:
pr-42 - Database:
branch_pr_42
Using PR Branches
Section titled “Using PR Branches”Via HTTP Header
Section titled “Via HTTP Header”curl http://localhost:8080/api/v1/tables/users \ -H "X-Fluxbase-Branch: pr-42"In CI/CD
Section titled “In CI/CD”Set the branch in your CI environment:
# GitHub Actions examplesteps: - name: Run tests env: FLUXBASE_BRANCH: pr-${{ github.event.number }} run: npm testIn Application Code
Section titled “In Application Code”const client = createClient(FLUXBASE_URL, API_KEY, { headers: { 'X-Fluxbase-Branch': `pr-${prNumber}` }})Troubleshooting
Section titled “Troubleshooting”Branch Not Created
Section titled “Branch Not Created”- Check webhook delivery in GitHub (Settings > Webhooks > Recent Deliveries)
- Verify Fluxbase logs for errors
- Ensure
auto_create_on_pris enabled - Check if max branches limit reached
Signature Verification Failed
Section titled “Signature Verification Failed”- Verify webhook secret matches in both GitHub and Fluxbase
- Check for whitespace in the secret
- Ensure using SHA-256 (not SHA-1)
Branch Not Deleted
Section titled “Branch Not Deleted”- Check if
auto_delete_on_mergeis enabled - Verify the PR was closed (not just updated)
- Check Fluxbase logs for deletion errors
Webhook Returns 401
Section titled “Webhook Returns 401”Repository not configured or signature mismatch. Configure the repository:
curl -X POST http://localhost:8080/api/v1/admin/branches/github/configs \ -H "Authorization: Bearer $SERVICE_KEY" \ -H "Content-Type: application/json" \ -d '{"repository": "owner/repo"}'API Reference
Section titled “API Reference”Webhook Endpoint
Section titled “Webhook Endpoint”POST /api/v1/webhooks/github
No authentication required (uses signature verification).
Headers:
| Header | Description |
|---|---|
X-GitHub-Event | Event type (e.g., pull_request) |
X-GitHub-Delivery | Unique delivery ID |
X-Hub-Signature-256 | HMAC-SHA256 signature |
Response:
{ "status": "created", "branch_id": "...", "branch_slug": "pr-42", "database": "branch_pr_42", "pr_number": 42}Limitations
Section titled “Limitations”- One branch per PR (reopening uses existing branch if present)
- Branch data is not persisted after deletion