From de6267700ecc3f9ffa4e770962ced14303a46407 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Sun, 10 May 2015 13:38:47 -0400 Subject: [PATCH] Fix bugs with the custom git trigger and make error reporting better --- endpoints/trigger.py | 13 +++++++------ endpoints/webhooks.py | 7 +++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/endpoints/trigger.py b/endpoints/trigger.py index 4fed791f6..45b286203 100644 --- a/endpoints/trigger.py +++ b/endpoints/trigger.py @@ -991,7 +991,7 @@ class CustomBuildTrigger(BuildTriggerHandler): 'required': ['url', 'message', 'date'], }, }, - 'required': ['commits', 'ref', 'default_branch'], + 'required': ['commit', 'ref', 'default_branch'], } @classmethod @@ -1005,15 +1005,15 @@ class CustomBuildTrigger(BuildTriggerHandler): try: metadata = json.loads(payload) validate(metadata, self.payload_schema) - except: - raise InvalidPayloadException() + except Exception as e: + raise InvalidPayloadException(e.message) return metadata def handle_trigger_request(self, request): # Skip if there is no payload. - payload = request.get_json() + payload = request.data if not payload: - raise SkipRequestException() + raise InvalidPayloadException() logger.debug('Payload %s', payload) @@ -1028,9 +1028,10 @@ class CustomBuildTrigger(BuildTriggerHandler): prepared = PreparedBuild(self.trigger) prepared.tags_from_ref(metadata['ref']) - prepared.name_from_sha(metadata['commit_sha']) + prepared.name_from_sha(metadata['commit']) prepared.subdirectory = config['subdir'] prepared.metadata = metadata + prepared.is_manual = False return prepared diff --git a/endpoints/webhooks.py b/endpoints/webhooks.py index 913b00fb0..bec7160e9 100644 --- a/endpoints/webhooks.py +++ b/endpoints/webhooks.py @@ -89,14 +89,17 @@ def build_trigger_webhook(trigger_uuid, **kwargs): try: prepared = handler.handle_trigger_request(request) except ValidationRequestException: + logger.debug('Handler reported a validation exception: %s', handler) # This was just a validation request, we don't need to build anything return make_response('Okay') except SkipRequestException: + logger.debug('Handler reported to skip the build: %s', handler) # The build was requested to be skipped return make_response('Okay') - except InvalidPayloadException: + except InvalidPayloadException as ipe: + logger.exception('Invalid payload') # The payload was malformed - abort(400) + abort(400, message=ipe.message) pull_robot_name = model.get_pull_robot_name(trigger) repo = model.get_repository(namespace, repository)