Public
Store GitHub webhooks in SQLite; add collaborator on repo create
githubsqlitewebhook
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Receives GitHub webhooks and:
- Default case — stores every webhook in a SQLite table (
webhooks) and acknowledges it with200 OK. - Special case — when a new repository is created (
repositoryevent,action: created), automatically adds a configured collaborator to that repository via the GitHub API.
The webhook endpoint is live at:
https://github-webhook-collab.val.run/
Set these on the val:
GITHUB_WEBHOOK_SECRET— a high-entropy secret used to verify webhook signatures. Set the same value on GitHub (Step 2). Optional but strongly recommended; without it the endpoint trusts any payload.COLLABORATOR— the GitHub username to add as a collaborator on newly created repositories.GITHUB_TOKEN— a token that can invite collaborators toownersrepos. Use a classic PAT withrepoadmin scope, or a fine-grained PAT granted Administration → Read and write on the relevant repositories.
👉 Add GITHUB_WEBHOOK_SECRET here: https://www.val.town/x/heidi/github-webhook-collaborator/environment-variables?key=GITHUB_WEBHOOK_SECRET 👉 Add COLLABORATOR here: https://www.val.town/x/heidi/github-webhook-collaborator/environment-variables?key=COLLABORATOR 👉 Add GITHUB_TOKEN here: https://www.val.town/x/heidi/github-webhook-collaborator/environment-variables?key=GITHUB_TOKEN
- Go to your repo (or org) → Settings → Webhooks → Add webhook.
- Payload URL: your val's endpoint https://github-webhook-collab.val.run/
- Content type:
application/json. - Secret: the same
GITHUB_WEBHOOK_SECRETvalue. - Which events: select Repositories (delivers the
repositorywebhook). For broader logging of all events, select "Send me everything". - Save.
- The default path writes each event to SQLite so you keep a complete audit trail.
repository+createdevents trigger the collaborator invite. The collaborator is grantedwritepermission.
main.ts— HTTP handler: verifies signature, stores the event, routes the repository-created case.db.ts— SQLite schema and insert helper.github.ts— calls the GitHub API to add a collaborator.