PyTux

Trips of a curious penguin.

Hello, time traveler! You are reading an article that is almost ten years old. The world has changed, and so have I and my opinions. There is a good chance what's below is not current, correct, or secure anymore, and maybe it never was. This page is preserved because I am an archivist at heart, but you have been warned.

A Python GitHub Push WebHook Handler

GitHub offers a number of Service Hooks that trigger actions when someone pushes to your repository. The generic hook is a simple WebHook that you can easily handle on your server.

There is a official Rack handler somewhere, and maybe a Django one, but nothing in pure Python. So here is it.

It’s pretty simple and self-contained, start it with the IP address and port to listen on as arguments, and it will pass a function - handle_hook() - the payload received on each push as a Python dictionary. It also checks that the originating IP is actually GH.

Then simply enter the address of your server on the GH Service Hooks repo Admin page, and you’re all set.

The Webhooks admin page

For reference on what’s inside the payload, RTFM.