Configuring web hooks

Web Hooks allow you to post changeset information to a specific URL. For each commit indexed by FishEye, the changeset data will be sent in JSON format to all configured URLs using a POST request.

You can use this feature to build integration with applications such as issue trackers, continuous integration solutions or notification systems.

Be aware that Web Hooks can expose private commit information. For example, using a public service could expose your code. Any user with administrative privileges in FishEye can create a Web Hook for any repository.

Adding web hooks

Web Hooks can be added or edited from the configuration page accessible from the Administration interface.

Go to the Admin area and click Web Hooks, under 'Repository Settings'.

Click Add to create a new Web Hook. Choose a repository and enter your URL. Click Test and Save to verify and store your configuration. Web Hooks also support basic authentication, which can be configured in the Advanced Options:

Disabling web hooks

To disable Web Hooks, go to the Administration interface > Plugins

Show System Plugins and navigate to the FishEye/Crucible Web Hooks Plugin and click Disable.

Demonstration of web hooks

PostBin is a service for debugging web hooks.

This is a public service and we do not recommend testing private repositories with public services as your code can be exposed.

Start by going to http://www.postbin.org and click Make a PostBin.

Grab your PostBin URL and create a Web Hook with it using a test repository.

When you click Test a dummy changeset will be sent to the PostBin URL. Refresh your PostBin page and you should see the data sent by FishEye.

This is a demonstration of the data sent by FishEye with a configured WebHook. The next step would be to write a service which captures this data and processes it.

Web hook data

Web Hooks will send changeset data in the following JSON representation:

{
    "repository": { 
        "name" : <repository name>,
        "displayName" : <repository display name>,
    },
    "changeset" : {
        "csid" : <changeset id>,
        "displayId" : <changeset id>,
        "author" : <committer>,
        "comment" : <commit message>,
        "date" : <commit date>,
        "branches" : [ 
            <list of commit branches>
        ],
        "tags" : [ 
            <list of commit tags>
        ],
        "parents" : [
            <list of parents>
        ] 
    }
}

Sample web hook scripts

The following script examples show you how to set up Web Hooks in various languages.

Python

This example requires the simplejson library.

import simplejson as json
import pprint
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer


class postRequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
                content_length = self.headers.getheader('content-length')
                if content_length:
                         content_length = int(content_length)
                if self.path.endswith('webhook'):
                        self.send_response(200)
                        self.end_headers()
                        body = self.rfile.read(content_length)
                        post_data = json.loads(body)
                        print 'Commit added with comment: %s' % post_data["changeset"]["comment"]

                else:
                        self.send_error(404, 'File Not Found %s' % self.path)
                
                return
                
                
def run():
        server = HTTPServer(('', 8081), postRequestHandler)
        print 'Server started'
        server.serve_forever()
                
if __name__ == '__main__':
        run()

Ruby and Sinatra

The example below will display the changeset information in the logs of the Sinatra server.

require 'rubygems'
require 'sinatra'
require 'json'

post '/' do
 changeset = JSON.parse(request.body.read)
 puts changeset.inspect 
end

Was this helpful?

Thanks for your feedback!

Why was this unhelpful?

Have a question about this article?

See questions about this article

Powered by Confluence and Scroll Viewport