Skip to content

Commit

Permalink
Document the Google Code Web Hook handler and make the branch returne…
Browse files Browse the repository at this point in the history
…d an option

- You can now choose the branch returned by the web hook handler with
  the 'branch' option;
- Also, check if a 'branch' field exists in the JSON dictionary sent by
  Google Code (in the hope that they add it one day…);
- Adjust test accordingly.
  • Loading branch information
lopter committed Dec 18, 2011
1 parent 350a3b0 commit 0a812c5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
13 changes: 10 additions & 3 deletions master/buildbot/status/web/hooks/googlecode.py
Expand Up @@ -28,9 +28,10 @@ class GoogleCodeAuthFailed(Exception):
pass

class Payload(object):
def __init__(self, headers, body):
def __init__(self, headers, body, branch):
self._auth_code = headers['Google-Code-Project-Hosting-Hook-Hmac']
self._body = body # we need to save it if we want to authenticate it
self._branch = branch

payload = json.loads(body)
self.project = payload['project_name']
Expand All @@ -57,7 +58,8 @@ def changes(self):
links=[r['url']],
revision=r['revision'],
when=r['timestamp'],
branch='default', # missing in the body
# Let's hope Google add the branch one day:
branch=r.get('branch', self._branch),
revlink=r['url'],
repository=self.repository,
project=self.project
Expand All @@ -70,7 +72,12 @@ def getChanges(request, options=None):
headers = request.received_headers
body = request.content.getvalue()
#logging.error('headers = {0}, body = {1}'.format(headers, body))
payload = Payload(headers, body)

# Instantiate a Payload object: this will parse the body, get the
# authentication code from the headers and remember the branch picked up
# by the user (Google Code doesn't send on which branch the changes were
# made)
payload = Payload(headers, body, options.get('branch', 'default'))

if 'secret_key' in options:
if not payload.authenticate(options['secret_key']):
Expand Down
Expand Up @@ -59,7 +59,12 @@ def setUp(self):
'Content-Type': 'application/json; charset=UTF-8'
}

self.changeHook = change_hook.ChangeHookResource(dialects={'googlecode' : {'secret_key': 'FSP3p-Ghdn4T0oqX'}})
self.changeHook = change_hook.ChangeHookResource(dialects={
'googlecode': {
'secret_key': 'FSP3p-Ghdn4T0oqX',
'branch': 'test'
}
})

# Test 'base' hook with attributes. We should get a json string representing
# a Change object as a dictionary. All values show be set.
Expand All @@ -78,7 +83,7 @@ def check_changes(r):
self.assertEquals(change["who"], "Louis Opter <louis@lse.epitech.net>")
self.assertEquals(change["revision"], '68e5df283a8e751cdbf95516b20357b2c46f93d4')
self.assertEquals(change["comments"], "Print a message")
self.assertEquals(change["branch"], "default")
self.assertEquals(change["branch"], "test")
self.assertEquals(change["revlink"], "http://webhook-test.googlecode.com/hg-history/68e5df283a8e751cdbf95516b20357b2c46f93d4/")

d.addCallback(check_changes)
Expand Down
4 changes: 2 additions & 2 deletions master/docs/manual/cfg-changesources.rst
Expand Up @@ -1125,8 +1125,8 @@ Change Hooks (HTTP Notifications)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Buildbot already provides a web frontend, and that frontend can easily be used
to receive HTTP push notifications of commits from services like GitHub. See
:ref:`Change-Hooks` for more information.
to receive HTTP push notifications of commits from services like GitHub or
GoogleCode. See :ref:`Change-Hooks` for more information.

.. bb:chsrc:: GoogleCodeAtomPoller
Expand Down
27 changes: 27 additions & 0 deletions master/docs/manual/cfg-statustargets.rst
Expand Up @@ -682,6 +682,33 @@ Note that there is a standalone HTTP server available for receiving GitHub
notifications, as well: :file:`contrib/github_buildbot.py`. This script may be
useful in cases where you cannot expose the WebStatus for public consumption.

Google Code hook
################

The Google Code hook is quite similar to the GitHub Hook. It has one option
for the "Post-Commit Authentication Key" used to check if the request is
legitimate::

c['status'].append(html.WebStatus(
…,
change_hook_dialects={'googlecode': {'secret_key': 'FSP3p-Ghdn4T0oqX'}}
))

This will add a "Post-Commit URL" for the project in the Google Code
administrative interface, pointing to ``/change_hook/googlecode`` relative to
the root of the web status.

Alternatively, you can use the :ref:`GoogleCodeAtomPoller` :class:`ChangeSource`
that periodically poll the Google Code commit feed for changes.

.. note::

Google Code doesn't send the branch on which the changes were made. So, the
hook always returns ``'default'`` as the branch, you can override it with the
``'branch'`` option::

change_hook_dialects={'googlecode': {'secret_key': 'FSP3p-Ghdn4T0oqX', 'branch': 'master'}}

.. bb:status:: MailNotifier
.. index:: single: email; MailNotifier
Expand Down

0 comments on commit 0a812c5

Please sign in to comment.