Skip to content

GitHub Integration

Fluxbase can automatically create and delete database branches when GitHub pull requests are opened, closed, or merged.

When integrated with GitHub:

  1. PR Opened/Reopened - Creates a database branch named pr-{number}
  2. PR Closed/Merged - Deletes the associated branch

This enables isolated preview environments for each pull request.

Register your GitHub repository with Fluxbase:

Terminal window
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"
}'
  1. Go to your repository Settings > Webhooks
  2. Click Add webhook
  3. Configure:
    • Payload URL: https://your-fluxbase-server.com/api/v1/webhooks/github
    • Content type: application/json
    • Secret: Same as webhook_secret above
    • Events: Select “Pull requests”
  4. Click Add webhook

Create a test PR and check the Fluxbase logs:

Terminal window
fluxbase branch list

You should see a new branch named pr-{number}.

FieldTypeDefaultDescription
repositorystringRequiredGitHub repository (owner/repo)
webhook_secretstring-Webhook signature secret
auto_create_on_prbooltrueCreate branch on PR open
auto_delete_on_mergebooltrueDelete branch on PR close
default_data_clone_modestringschema_onlyClone mode for PR branches

GitHub signs webhook payloads with HMAC-SHA256. Fluxbase verifies signatures when webhook_secret is configured.

Behavior:

Secret ConfiguredSignature SentResult
YesYes (valid)Accepted
YesYes (invalid)Rejected
YesNoRejected
NoYesAccepted (with warning)
NoNoRejected*

*Unconfigured repositories are rejected to prevent abuse. Configure the repository first.

  1. Always configure a webhook secret - Use a strong, random secret
  2. Use HTTPS - Never send webhooks over plain HTTP
  3. Rotate secrets periodically - Update both GitHub and Fluxbase config

Generate a secure secret:

Terminal window
openssl rand -hex 32
EventActionResult
pull_requestopenedCreate branch pr-{number}
pull_requestreopenedCreate branch if not exists
pull_requestclosedDelete branch
pull_requestsynchronize(Acknowledged, no action)
ping-Returns “pong”

All other events are acknowledged but ignored.

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
Terminal window
curl http://localhost:8080/api/v1/tables/users \
-H "X-Fluxbase-Branch: pr-42"

Set the branch in your CI environment:

# GitHub Actions example
steps:
- name: Run tests
env:
FLUXBASE_BRANCH: pr-${{ github.event.number }}
run: npm test
const client = createClient(FLUXBASE_URL, API_KEY, {
headers: {
'X-Fluxbase-Branch': `pr-${prNumber}`
}
})
  1. Check webhook delivery in GitHub (Settings > Webhooks > Recent Deliveries)
  2. Verify Fluxbase logs for errors
  3. Ensure auto_create_on_pr is enabled
  4. Check if max branches limit reached
  1. Verify webhook secret matches in both GitHub and Fluxbase
  2. Check for whitespace in the secret
  3. Ensure using SHA-256 (not SHA-1)
  1. Check if auto_delete_on_merge is enabled
  2. Verify the PR was closed (not just updated)
  3. Check Fluxbase logs for deletion errors

Repository not configured or signature mismatch. Configure the repository:

Terminal window
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"}'

POST /api/v1/webhooks/github

No authentication required (uses signature verification).

Headers:

HeaderDescription
X-GitHub-EventEvent type (e.g., pull_request)
X-GitHub-DeliveryUnique delivery ID
X-Hub-Signature-256HMAC-SHA256 signature

Response:

{
"status": "created",
"branch_id": "...",
"branch_slug": "pr-42",
"database": "branch_pr_42",
"pr_number": 42
}
  • One branch per PR (reopening uses existing branch if present)
  • Branch data is not persisted after deletion