github-hooker

Simple github webhooks handler


Keywords
github, webhooks, python, handler
License
GPL-2.0
Install
pip install github-hooker==0.2

Documentation

github-hooker

Easily handle github hooks. This package allows easily handling github webhooks by running a simple bottle webserver to handle requests coming from github. All it requires is a module containing functions with predefined names to handle the github event transmitted via webhook.

The webhook at Github should be configured to send event data as JSON and not as url form encoded.

Example:

github_hooker -c config.json -m github_actions.py

Config file needs to contain host, port and url_path parameters. See config.json under example folder. The module file should define functions for handling github events. Event handler functions accept a single parameter which is a request object.

Example of a function to handle repository pushed event:

def on_event_push(request):

    branch = request.json.get('ref').split('/')[-1]

    if 'master' == branch:
        print("changes pushed to master branch")

        pusher = request.json.get('pusher')
        print("Pushed by {} ({})".format(pusher['name'], pusher['email']))

        hc = request.json.get('head_commit')
        print("Head commit: %s" % hc['id'])
        print("  By: %s (%s)" % (hc['committer']['name'], hc['committer']['email']))
        print("  on: %s" % hc['timestamp'])
        print("  %s" % hc['message'])