mirror of https://github.com/zulip/zulip.git
github refactor: Use early-exit idiom.
We also comment a bit more explicitly about the None case.
This commit is contained in:
parent
5c916135c9
commit
0d9b1817f9
|
@ -554,17 +554,25 @@ def api_github_webhook(
|
||||||
branches: Optional[str]=REQ(default=None),
|
branches: Optional[str]=REQ(default=None),
|
||||||
user_specified_topic: Optional[str]=REQ("topic", default=None)) -> HttpResponse:
|
user_specified_topic: Optional[str]=REQ("topic", default=None)) -> HttpResponse:
|
||||||
event = get_event(request, payload, branches)
|
event = get_event(request, payload, branches)
|
||||||
if event is not None:
|
if event is None:
|
||||||
subject = get_subject_based_on_type(payload, event)
|
# This is nothing to worry about--get_event() returns None
|
||||||
body_function = get_body_function_based_on_type(event)
|
# for events that are valid but not yet handled by us.
|
||||||
if 'include_title' in signature(body_function).parameters:
|
# See IGNORED_EVENTS, for example.
|
||||||
body = body_function(
|
return json_success()
|
||||||
payload,
|
|
||||||
include_title=user_specified_topic is not None,
|
subject = get_subject_based_on_type(payload, event)
|
||||||
)
|
|
||||||
else:
|
body_function = get_body_function_based_on_type(event)
|
||||||
body = body_function(payload)
|
|
||||||
check_send_webhook_message(request, user_profile, subject, body)
|
if 'include_title' in signature(body_function).parameters:
|
||||||
|
body = body_function(
|
||||||
|
payload,
|
||||||
|
include_title=user_specified_topic is not None,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
body = body_function(payload)
|
||||||
|
|
||||||
|
check_send_webhook_message(request, user_profile, subject, body)
|
||||||
return json_success()
|
return json_success()
|
||||||
|
|
||||||
def get_event(request: HttpRequest, payload: Dict[str, Any], branches: Optional[str]) -> Optional[str]:
|
def get_event(request: HttpRequest, payload: Dict[str, Any], branches: Optional[str]) -> Optional[str]:
|
||||||
|
|
Loading…
Reference in New Issue