Skip to main content

GitHub webhook on localhost

GitHub sends webhooks about repository or organization events: pushes, pull requests, comments, releases. To receive them in an app on your machine, you need a public address. tuna provides it and can verify the request signature for you.

Step 1. Install the client​

Instructions are available on the installation page.

Step 2. Run the app​

Start your webhook handler, for example on port 8080 and path /github. The payloads are described in the GitHub documentationOpens in a new tab, and the event type comes in the X-GitHub-Event header.

Step 3. Start tuna​

Come up with a secret β€” you'll enter the same one in GitHub. With the --verify-webhook flag, tuna checks the X-Hub-Signature-256 signature and doesn't let requests without a valid signature through to the app; they get 401:

tuna http 8080 --subdomain=<your-subdomain> --verify-webhook=github --verify-webhook-secret=<secret>

The free permanent subdomain keeps the address the same across restarts, so you don't have to edit the webhook settings.

Step 4. Create the webhook​

In the repository, open Settings β†’ Webhooks β†’ Add webhook. For an organization, do the same in the organization settings.

  • Payload URL: the tunnel address and path, https://<your-subdomain>.a.tuna.free/github;
  • Content type: application/json;
  • Secret: the secret from step 3;
  • events: the ones your app needs.

Once you save it, GitHub immediately sends a ping event.

Step 5. Check​

The ping event shows up in the inspector at http://127.0.0.1:4040 along with the app's response. If the signature didn't match, the request has a Policy label: check that the secret in GitHub matches --verify-webhook-secret.

GitHub keeps a history too: the Recent Deliveries tab in the webhook settings shows the request, the response and a Redeliver button.

To run the same event again after changing the code, click Replay in the inspector. The body goes out byte for byte, so the signature still matches on replay, and you don't need to trigger anything in GitHub.

GitHub waits for a response for a limited time. If processing takes long, respond 200 right away and handle the event in the background.

If it doesn't arrive, follow the steps in Webhook doesn't reach the app.