integrations: Prevent duplicate GitHub pull request review messages.

GitHub sends two almost identical payloads when a pull
request is reviewed, which results in two duplicative
notification messages.

The payloads have different "action" value, with one
having the "submitted" action, whereas the other is
"edited" and has an empty "changes" dict.

We now ignore the payload with the "edited" action type
and an empty "changes" dict.

Fixes #26145.

Co-authored-by: Pieter CK <pieterceka123@gmail.com>
This commit is contained in:
lumpleme
2024-05-26 21:38:01 -03:00
committed by Tim Abbott
parent 76df435dab
commit b5c63cfb85
3 changed files with 533 additions and 0 deletions

View File

@@ -940,6 +940,12 @@ def api_github_webhook(
return json_success(request)
def is_empty_pull_request_review_event(payload: WildValue) -> bool:
action = payload["action"].tame(check_string)
changes = payload.get("changes", {})
return action == "edited" and len(changes) == 0
def get_zulip_event_name(
header_event: str,
payload: WildValue,
@@ -970,6 +976,14 @@ def get_zulip_event_name(
return "pull_request_auto_merge"
if action in IGNORED_PULL_REQUEST_ACTIONS:
return None
elif header_event == "pull_request_review":
if is_empty_pull_request_review_event(payload):
# When submitting a review, GitHub has a bug where it'll
# send a duplicate empty "edited" event for the main
# review body. Ignore those, to avoid triggering
# duplicate notifications.
return None
return "pull_request_review"
elif header_event == "push":
if is_merge_queue_push_event(payload):
return None