# HG changeset patch # User Marcin Kuzminski # Date 2017-02-01 11:07:21 # Node ID 9900f5ed55ddd42a5b5f4b31f5a21f27e21f841e # Parent d35c11300f7ecb195cae237ff4e1400a1ed36db5 webhook: add possibility to use POST or GET methods for calling webhooks. diff --git a/rhodecode/integrations/types/webhook.py b/rhodecode/integrations/types/webhook.py --- a/rhodecode/integrations/types/webhook.py +++ b/rhodecode/integrations/types/webhook.py @@ -173,6 +173,18 @@ class WebhookSettingsSchema(colander.Sch placeholder='secret_token' ), ) + method_type = colander.SchemaNode( + colander.String(), + title=_('Call Method'), + description=_('Select if the webhook call should be made ' + 'with POST or GET.'), + default='post', + missing='', + widget=deform.widget.RadioChoiceWidget( + values=[('get', 'GET'), ('post', 'POST')], + inline=True + ), + ) class WebhookIntegrationType(IntegrationTypeBase): @@ -225,11 +237,11 @@ class WebhookIntegrationType(Integration url_calls = handler(event, data) log.debug('webhook: calling following urls: %s', [x[0] for x in url_calls]) - post_to_webhook(url_calls) + post_to_webhook(url_calls, self.settings) @task(ignore_result=True) -def post_to_webhook(url_calls): +def post_to_webhook(url_calls, settings): max_retries = 3 for url, token, data in url_calls: # retry max N times @@ -241,8 +253,13 @@ def post_to_webhook(url_calls): req_session.mount( 'http://', requests.adapters.HTTPAdapter(max_retries=retries)) - resp = req_session.post(url, json={ + method = settings.get('method_type') or 'post' + call_method = getattr(req_session, method) + + log.debug('calling WEBHOOK with method: %s', call_method) + resp = call_method(url, json={ 'token': token, 'event': data }) + log.debug('Got WEBHOOK response: %s', resp) resp.raise_for_status() # raise exception on a failed request