Skip to content

Using web-hooks

Web-hooks are a notification system that could be compared to a callback. Basically, SourceLab will make a HTTP POST request to one or more third party server/application with information about what is or just happened.

Activating web-hooks notifications

To set-up a web-hook, simply go to the settings page of your project and enter the URL to the server/endpoint that will receive the notifications. If you wish to enter multiple URLs, enter one per line. To stop all notifications, clear out that field.

SourceLab will send a notification to this/these URL(s) for every action made on this project: new issue, new pull-request, new comments, new commits...

Note

The notifications sent via web-hooks have the same payload as the notifications sent via fedmsg. Therefore, the list of SourceLab topics as well as example messages can be found in the fedmsg documentation about SourceLab

Authenticating the notifications

There is, in the settings page, a web-hook key which is used by the server (here SourceLab) to sign the message sent and which you can use to ensure the notifications received are coming from the right source.

Each POST request made contains some specific headers:

X-SourceLab
X-SourceLab-Project
X-SourceLab-Signature
X-SourceLab-Signature-256
X-SourceLab-Topic

X-SourceLab contains URL of the SourceLab instance sending this notification.

X-SourceLab-Project contains the name of the project on that SourceLab instance.

X-SourceLab-Signature contains the signature of the message allowing to check that the message comes from SourceLab.

X-SourceLab-Signature-256 contains the SHA-256 signature of the message allowing to check that the message comes from SourceLab.

Note

These headers are present to allow you to verify that the webhook was actually sent by the correct SourceLab instance. These are not included in the signed data.

X-SourceLab-Topic is a global header giving a clue about the type of action that just occurred. For example issue.edit.

Warning

The headers X-SourceLab, X-SourceLab-Project and X-SourceLab-Topic are present for convenience only, they are not signed and therefore should not be trusted. Rely on the payload after checking the signature to make any decision.

SourceLab relies on hmac to sign the content of its messages. If you want to validate the message, in python, you can do something like the following:

import hmac
import hashlib

payload =  # content you received in the POST request
headers =  # headers of the POST request
project_web_hook_key =  # private web-hook key of the project

hashhex = hmac.new(
    str(project_web_hook_key), payload, hashlib.sha1).hexdigest()

if hashhex != headers.get('X-SourceLab-Signature'):
    raise Exception('Message received with an invalid signature')