Skills, MCP and apps / Apps and webhooks
Send repository events to another service
Your chat bot must post when someone pushes to main, or your deploy service must start when a CI run ends. A webhook does this: on each event that you pick, Source sends a signed POST request to the URL of your service.
4 min read
You need:
- Admin access to the repository.
The webhooks are in Settings, under Integrations, at Webhooks (/@<owner>/<repo>/settings/webhooks).
1. Add a webhook
On the web:
- Open the repository, then Settings, then Webhooks.
- Click Add webhook.
- In Payload URL, type the URL of your receiver. Under Events, pick the events to send.
- Leave Secret empty, then click Add webhook. Source makes a secret.
- Copy the secret from the box at the top of the page. It shows only now. Give it to your receiver.
In a terminal, give --event once for each event:
src webhook create --url https://bot.example.com/source --event push --event pull_request
src prints the secret alone on standard output, once. To use your own secret of 8 to 256 characters, pipe it in. Then src does not print it:
src webhook create --url https://bot.example.com/source --event push --secret - < secret.txt
The events, by their name on the web and in src:
| On the web | Event | Sent when |
|---|---|---|
| Pushes | push | A branch or a tag is created, moved or deleted. |
| Issues | issues | An issue is opened, edited, closed, reopened, labeled, unlabeled, assigned or unassigned. |
| Pull requests | pull_request | The same as issues, and also when a draft is ready for review, when the head gets new commits, and when it is merged. |
| Comments | issue_comment | A comment on an issue or a pull request is created or edited. |
| Reviews | pull_request_review | A review of a pull request is submitted. |
| CI runs | ci_run | A CI run starts or ends. |
Source refuses a URL that breaks one of these rules:
- It uses
httpson port 443. - It has no user name or password, and no
#part. A query string works, for example?token=abc. - It is not a local, private or internal address.
- It is not the address of TanStack Source itself.
Note
Source does not follow redirects. A 301 or a 302 answer counts as a failure.
2. Test it with a ping
A new webhook that is on gets a ping at once. To send another one:
- On the web, click Send ping on the row of the webhook.
- In a terminal, run
src webhook ping <id>.src webhook listshows the id of each webhook.
Your receiver must answer within 10 seconds with a 2xx status. To check the signature of each request, see Webhook events and payloads.
Done
Your service gets a signed POST request for each event that you picked. Later, read and resend the deliveries, or rotate, change or delete the webhook.
What a webhook does not send
A webhook sends only what every reader of the repository can see:
- An issue or a pull request that screening holds sends nothing. When screening releases it, it sends
opened. - A private pull request sends nothing until it is public. Comments and reviews on such items send nothing.
- A hidden workflow never sends
ci_run.
Some changes send no event:
- A deleted comment.
- A merge done on GitHub, in a repository that is synced with GitHub. It sends no
push. - A branch that is deleted on the web. It sends no
push.
Limits
- A repository has at most 20 webhooks.
- One push sends at most 20
pushevents: branches first, then tags. A push that moves more refs sends no events for the rest. - A webhook has at most 1,000 pending deliveries. Past that, a new event gets no delivery for that webhook.
REST and MCP
An agent or a script does the same work over REST or MCP, with the same rules. A path that starts with ... is under /api/v1/repos/{owner}/{repo}.
| You want to | REST | MCP tool |
|---|---|---|
| List or add webhooks | GET or POST .../hooks | list_repo_webhooks, create_repo_webhook |
| Change or delete a webhook | PATCH or DELETE .../hooks/{id} | update_repo_webhook, delete_repo_webhook |
| Send a ping | POST .../hooks/{id}/pings | ping_repo_webhook |
| Rotate the secret | POST .../hooks/{id}/secret | rotate_repo_webhook_secret |
| List the deliveries | GET .../hooks/{id}/deliveries | list_repo_webhook_deliveries |
| Send a delivery again | POST .../hooks/{id}/deliveries/{delivery}/attempts | redeliver_repo_webhook |
Use the REST API has the request bodies and the answers.