Skip to content
A very simple Gitlab post-receive web hook handler.
Branch: master
Clone or download
Pull request Compare This branch is 28 commits ahead, 11 commits behind razius:master.
Latest commit cb578d1 Oct 17, 2017
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE update docs Feb 23, 2016 commit parsing and issue label modification support Oct 8, 2017
gwh.initd fix #4: initd example Nov 13, 2016
repos.json.example fix example key Jan 24, 2017
test.json Added a test gitlab hook json Aug 5, 2016

Flask webhook for Gitlab

A very simple post-receive web hook handler.

It will optionally verify that the POST request originated from a particular IP address.

Getting started

Installation Requirements

Install dependencies found in requirements.txt.

pip install -r requirements.txt

Repository Configuration

Create a JSON config file (e.g., repos.json) to configure repositories. Each repository must be keyed by its Gitlab homepage.

    "": {
    	"private_token": "xxxxxxxxxxxxx",
        "push": {
            "master": {
                "path": "/home/spm-batching/deploy",
                "actions": [
                  "git checkout master",
                  "git pull"
            "other": {
            	"actions": [
            		"echo A non-master branch was pushed."
        "issue": {
            "user_notify": [
                "\\*\\*Sender\\*\\*\\: ([a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\\.[a-zA-Z0-9-.]+)",
            "labels": []

This example handles several types of webhooks.

  1. push: After a push event to the repo master branch, it executes a couple of command in the local shell to pull in the master HEAD. The special branch key other will run if the pushed branch is not otherwise matched to a key in the push hash.
  2. issue.user_notify: After a new issue event, the handler runs a regex match on the issue body and adds an issue comment to @mention the user by email.
  3. issue.labels: Parse the commit message to handle adding or removing labels based on commit messages. For instance, "address #53, #72: carousel accessibility fixes; -browser compat, +accessibility, ~Pending" will add an "accessibility" label (if it already exists for the project) to issues 53 and 72, remove label "browser compat", and add label "Pending" (presumably a list label) while removing other list labels (effectively moving an issue on the Gitlab boards kanban).

The issue hook uses a Gitlab private token to run API commands to lookup a username by email and add an issue comment. The push hook does not require the private token because it does not use the Gitlab API.


python --help

Example usage:

Assume a self-hosted Gitlab server on and a production webserver on The idea is that a push to the master branch for your project should trigger the production machine to pull in a new copy of the repo.

On your webhost (, bring up the webhook handler:

python -c repos.json -p 8080 --allow &

Then in your Gitlab server (on project settings, create a new webhook with URL that's triggered on push events.


curl -i -X POST -H "Content-Type: application/json" --data "@test.json" localhost:808
You can’t perform that action at this time.