Guide: How to handle GitHub webhook redeliveries without running the same job twice.
A FastAPI example for GitHub's native webhook headers. It verifies the raw body, persists a delivery receipt and a job together in PostgreSQL, then records a synthetic review result later. It never calls GitHub or writes to a repository. The only supported business event is opening a pull request in one configured repository.
Use Python 3.12 and an empty disposable PostgreSQL database. Set a different random secret for the GitHub body signature and the demo worker.
python -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt -r requirements-test.txt
export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/webhook_drill
export MIGRATION_DATABASE_URL="$DATABASE_URL"
export GITHUB_WEBHOOK_SECRET="$(python -c 'import secrets;print(secrets.token_urlsafe(32))')"
export DEMO_WORKER_KEY="$(python -c 'import secrets;print(secrets.token_urlsafe(32))')"
export DEMO_REPO_ID=12012026
python migrate.py
uvicorn app:app --port 8080In another shell with the same secrets and repo ID, run
python proof.py. It submits synthetic signed fixtures, not real GitHub
deliveries. Missing or invalid signatures, a different repository, and
conflicting receipt content write no new jobs. The same delivery ID
returns the original receipt. Two receipts for the same PR action
leave one job. The separate demo worker writes exactly one local effect.
Create a new private test app and attach a disposable database with
gregale add postgres --app YOUR_APP --with-migrations. If your first
deploy creates the app, use a scratch copy of the manifest containing
only hosting until the migration credential is attached. Then deploy
the original source with both manifest sections. The release task runs
python migrate.py using MIGRATION_DATABASE_URL and the app uses the
separate DATABASE_URL.
Seal the three demo settings using a mode-0600 secrets file outside the
source tree. Keep the app private. Set DEMO_BASE_URL to the HTTPS
app URL and DEMO_INVOKE_TOKEN to an invocation credential for this
disposable app. Run python proof.py with the same synthetic settings.
No GitHub registration or token is needed for this proof.
For a real integration, GitHub must be able to reach a dedicated HTTPS receiver without a Gregale bearer key. Keep the worker separate and private, and do not publish the demo admin routes. Subscribe only to the event types you handle. The native GitHub signature covers the body, not the delivery/event headers; use signed business fields for any operation-specific deduplication. Use retention, retries, monitoring and downstream idempotency appropriate to your real workflow.