mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
github: Add list and fixtures for ignored events to webhook.
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
from __future__ import absolute_import
|
||||
import re
|
||||
import logging
|
||||
from functools import partial
|
||||
from typing import Any, Callable, Text, Dict
|
||||
from typing import Any, Callable, Text, Dict, Optional
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from zerver.lib.actions import check_send_message
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.request import JsonableError
|
||||
from zerver.models import Client, UserProfile
|
||||
from zerver.decorator import api_key_only_webhook_view, REQ, has_request_variables
|
||||
|
||||
@@ -384,14 +386,14 @@ def api_github_webhook(
|
||||
payload=REQ(argument_type='body'), stream=REQ(default='github')):
|
||||
# type: (HttpRequest, UserProfile, Client, Dict[str, Any], Text) -> HttpResponse
|
||||
event = get_event(request, payload)
|
||||
if event != 'ping':
|
||||
if event != 'ping' and event is not None:
|
||||
subject = get_subject_based_on_type(payload, event)
|
||||
body = get_body_function_based_on_type(event)(payload)
|
||||
check_send_message(user_profile, client, 'stream', [stream], subject, body)
|
||||
return json_success()
|
||||
|
||||
def get_event(request, payload):
|
||||
# type: (HttpRequest, Dict[str, Any]) -> str
|
||||
# type: (HttpRequest, Dict[str, Any]) -> Optional[str]
|
||||
event = request.META['HTTP_X_GITHUB_EVENT']
|
||||
if event == 'pull_request':
|
||||
action = payload['action']
|
||||
@@ -401,6 +403,9 @@ def get_event(request, payload):
|
||||
return 'assigned_or_unassigned_pull_request'
|
||||
if action == 'closed':
|
||||
return 'closed_pull_request'
|
||||
if action in ('labeled', 'unlabeled', 'review_requested', 'review_request_removed'):
|
||||
logging.warn('Event pull_request with {} action is unsupported'.format(action))
|
||||
return None
|
||||
raise UnknownEventType(u'Event pull_request with {} action is unsupported'.format(action))
|
||||
if event == 'push':
|
||||
if is_commit_push_event(payload):
|
||||
|
||||
Reference in New Issue
Block a user