/GitlabHookReceiver

Receive Gitlab Hooks Through Twisted

Primary LanguagePython

Gitlab Hook Receiver

GitLab is pretty cool, and it even supports push hooks. But the way they're implemented, is that they send a POST request to a given url.

This simple receiver can launch a script (passed in as an argument during init) and/or contact Pushover on every recieved POST request, logs the request, as well as any output from the script. Its quite clean, and uses twisted's framework for calling the scripts.

There's no authentication, so use at your own risk, and preferably on an internal network. For some safety, no arguments are passed to the script. Pushover is a third party service, and if you enable it, some information will be passed to them in the pushover request.

Requirements

  • pyOpenSSL (for pushover support)

  • simplejson

  • twisted

Pushover

To use Pushover, edit pushover.json, which is an array of dictionaries with token/user. Messages will be sent to all token/user pairs. To have a nice icon: logo-black.png

ScreenShot

Installation

  • In Gitlab, add a web hook to point to the GitlabReceiver server, ie http://127.0.0.1:8504

  • Configure pushover.json with tokens and users

  • Launch the server (look at Usage)

Usage

GitLab.py contains the code that listens in for a POST request, launches the script, contacts Pushover, and does logging. As you may have noticed, it does not contain a main...instead you launch it using twistd

twistd is a neat way of daemonizing twisted servers, but suffers from a not so obvious way of how to pass in arguments. In this directory run:

twistd --help

You should see a Gitlab command show up in the Commands: list. This happens, because twisted/plugins/GitLab_plugin.py provides a service for twistd to run. If you open that file, you'll see that it does some argument checking, and starts the service. To see options provided by the GitLab receiver:

twistd GitLab --help

And finally to run, first pass in twistd arguments, then GitLab arguments. All GitLab arguments are optional.

twistd --pidfile=gitlab.pid -l gitlab.log GitLab --addr 127.0.0.1 --port 8504 --pushover pushover.json --script example.sh