2.6 KiB
2.6 KiB
Webhook Setup (Global and Repository-Only)
This bot accepts Gitea webhook events at:
POST /webhook/gitea
It only processes these event types:
issue_commentpull_request_comment
It verifies X-Gitea-Signature using GITEA_WEBHOOK_SECRET (HMAC-SHA256).
Prerequisites
- Bot is reachable from Gitea (example:
https://bot.example.com/webhook/gitea). GITEA_WEBHOOK_SECRETis set in your bot.env.ALLOWED_REPOSincludes repositories you want to allow (example:team/repo-a,team/repo-b).
Option A: Global Webhook (single webhook, recommended)
Use this when you want one webhook configuration for many repositories.
- In Gitea, open site administration webhook settings (instance-level/global webhooks).
- Add a new webhook of type
Gitea(JSON payload). - Set:
Payload URL:https://bot.example.com/webhook/giteaHTTP Method:POSTSecret: same value asGITEA_WEBHOOK_SECRETContent Type:application/json
- Enable only these events:
Issue commentPull request comment
- Save and use the webhook test/ping action.
- Set
WEBHOOK_MODE=globalin bot env (informational, for deployment clarity).
Notes:
- The bot still enforces
ALLOWED_REPOS; non-allowlisted repos are ignored. - A global webhook is usually easiest to operate at scale.
Option B: Repository-Only Webhook (per repository)
Use this when you want explicit repo-by-repo control.
- Open the repository in Gitea.
- Go to repository
Settings->Webhooks. - Add a new
Giteawebhook. - Set:
Payload URL:https://bot.example.com/webhook/giteaHTTP Method:POSTSecret: same value asGITEA_WEBHOOK_SECRETContent Type:application/json
- Enable only:
Issue commentPull request comment
- Save and test.
- Repeat for each repository.
- Set
WEBHOOK_MODE=repoin bot env.
Important:
- This bot has one configured secret (
GITEA_WEBHOOK_SECRET) per bot instance. - If multiple repo webhooks use different secrets, signature verification will fail for repos not matching the configured secret.
Minimal .env snippet
GITEA_WEBHOOK_SECRET=replace-with-random-secret
ALLOWED_REPOS=team/repo-a,team/repo-b
WEBHOOK_MODE=global
For repo-only mode, use WEBHOOK_MODE=repo.
Validation Checklist
GET /healthzreturns{"status":"ok"}.- Webhook deliveries from Gitea return HTTP
200(or bot returns accepted/ignored JSON, not401). 401 invalid signaturemeans webhook secret mismatch.{"accepted": false, "reason": "repo not allowed"}means updateALLOWED_REPOS.- A PR comment with
@codex reviewon an allowlisted repo queues a job.