From 6139e8948a250f6ceb415abd3c12a353e1754692 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sat, 7 May 2016 11:22:01 -0700 Subject: [PATCH] travis: User REQ framework for extracting JSON payload. --- zerver/views/webhooks/travis.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/zerver/views/webhooks/travis.py b/zerver/views/webhooks/travis.py index 9dbe3d5697..5f624b3ff2 100644 --- a/zerver/views/webhooks/travis.py +++ b/zerver/views/webhooks/travis.py @@ -4,15 +4,19 @@ from zerver.models import get_client from zerver.lib.actions import check_send_message from zerver.lib.response import json_success from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view - +from zerver.lib.validator import check_dict, check_string import ujson @api_key_only_webhook_view @has_request_variables -def api_travis_webhook(request, user_profile, stream=REQ(default='travis'), topic=REQ(default=None)): - message = ujson.loads(request.POST['payload']) - +def api_travis_webhook(request, user_profile, stream=REQ(default='travis'), + topic=REQ(default=None), + message=REQ('payload', validator=check_dict([ + ['author_name', check_string], + ['status_message', check_string], + ['compare_url', check_string], + ]))): author = message['author_name'] message_type = message['status_message'] changes = message['compare_url']