Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/github: Ignore unlabeled events sent on label deletion.
Niloth P22c132a119a4
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.pyindex 0c3e746c982..7fa413486c8 100644--- a/zerver/webhooks/github/tests.py+++ b/zerver/webhooks/github/tests.py@@ -656,6 +656,19 @@ A temporary team so that I can get some webhook fixtures!payload = self.get_body("pull_request_review__edited_empty_changes")self.verify_post_is_ignored(payload, "pull_request_review")+ def test_unlabeled_by_label_deletion_ignored(self) -> None:+ # GitHub omits the "label" field when a deleted label is+ # automatically removed from the items it was applied to.+ event_types_and_fixtures = [+ ("pull_request", "pull_request__unlabeled"),+ ("issues", "issues__unlabeled"),+ ("discussion", "discussion__unlabeled"),+ ]+ for http_x_github_event, fixture_name in event_types_and_fixtures:+ payload = orjson.loads(self.get_body(fixture_name))+ del payload["label"]+ self.verify_post_is_ignored(orjson.dumps(payload).decode(), http_x_github_event)+def test_ignored_team_actions(self) -> None:ignored_actions = ["added_to_repository",diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.pyindex 844dab93bef..9c3d3d8654e 100644--- a/zerver/webhooks/github/view.py+++ b/zerver/webhooks/github/view.py@@ -1211,15 +1211,22 @@ def api_github_webhook(# Ignore 'comment edited' events (except discussion comments)# if the comment body remains unchanged.+ action = payload.get("action", "").tame(check_string)if ("comment" in header_eventand "discussion" not in header_event- and payload.get("action", "").tame(check_string) == "edited"+ and action == "edited"and payload["changes"]["body"]["from"].tame(check_string)== payload["comment"]["body"].tame(check_string)):return json_success(request)+ # Deleting a label removes it from all issues, PRs, and discussions.+ # Suppress noisy per-item "unlabeled" notifications when the "label"+ # does not exist.+ if action == "unlabeled" and "label" not in payload:+ return json_success(request)+event = get_zulip_event_name(header_event, payload, branches)if event is None:# This is nothing to worry about--get_event() returns None