1# This file is part of Buildbot. Buildbot is free software: you can 2# redistribute it and/or modify it under the terms of the GNU General Public 3# License as published by the Free Software Foundation, version 2. 4# 5# This program is distributed in the hope that it will be useful, but WITHOUT 6# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 7# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 8# details. 9#10# You should have received a copy of the GNU General Public License along with11# this program; if not, write to the Free Software Foundation, Inc., 5112# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.13#14# Copyright 2011, Louis Opter <kalessin@kalessin.fr>1516# Quite inspired from the github hook.1718importhmac19fromtwisted.pythonimportlog20frombuildbot.utilimportjson21

27self._auth_code=headers['Google-Code-Project-Hosting-Hook-Hmac']28self._body=body# we need to save it if we want to authenticate it29self._branch=branch3031payload=json.loads(body)32self.project=payload['project_name']33self.repository=payload['repository_path']34self.revisions=payload['revisions']35self.revision_count=payload['revision_count']

67headers=request.received_headers68body=request.content.getvalue()6970# Instantiate a Payload object: this will parse the body, get the71# authentication code from the headers and remember the branch picked72# up by the user (Google Code doesn't send on which branch the changes73# were made)74payload=Payload(headers,body,options.get('branch','default'))7576if'secret_key'inoptions:77ifnotpayload.authenticate(options['secret_key']):78raiseGoogleCodeAuthFailed()79else:80log.msg("Missing secret_key in the Google Code WebHook options: "81"cannot authenticate the request!")8283log.msg('Received %d changes from Google Code'%84(payload.revision_count,))85changes=payload.changes()8687returnchanges,'Google Code'