Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
github webhook: Explicitly ignore team actions.
Steve Howell425db931a841
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.pyindex 287891983ce..f4d17ad370c 100644--- a/zerver/webhooks/github/tests.py+++ b/zerver/webhooks/github/tests.py@@ -369,6 +369,18 @@ A temporary team so that I can get some webhook fixtures!payload = orjson.dumps(data).decode()self.verify_post_is_ignored(payload, "pull_request")+ def test_ignored_team_actions(self) -> None:+ ignored_actions = [+ "added_to_repository",+ "created",+ "deleted",+ "removed_from_repository",+ ]+ for action in ignored_actions:+ data = dict(action=action)+ payload = orjson.dumps(data).decode()+ self.verify_post_is_ignored(payload, "team")+def test_push_1_commit_filtered_by_branches_ignore(self) -> None:self.url = self.build_webhook_url(branches='master,development')payload = self.get_body('push__1_commit')diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.pyindex 73f7d4b8165..959b05ecac0 100644--- a/zerver/webhooks/github/view.py+++ b/zerver/webhooks/github/view.py@@ -534,6 +534,18 @@ IGNORED_PULL_REQUEST_ACTIONS = ["unlabeled",]+IGNORED_TEAM_ACTIONS = [+ # These are actions that are well documented by github+ # (https://docs.github.com/en/developers/webhooks-and-events/webhook-events-and-payloads)+ # but we ignore them for now, possibly just due to laziness.+ # One curious example here is team/added_to_repository, which is+ # possibly the same as team_add.+ "added_to_repository",+ "created",+ "deleted",+ "removed_from_repository",+]+@api_key_only_webhook_view('GitHub', notify_bot_owner_on_invalid_json=True)@has_request_variablesdef api_github_webhook(@@ -584,6 +596,17 @@ def get_event(request: HttpRequest, payload: Dict[str, Any], branches: Optional[if payload['check_run']['status'] != 'completed':return Nonereturn event+ elif event == "team":+ action = payload["action"]+ if action == "edited":+ return "team"+ if action in IGNORED_TEAM_ACTIONS:+ # no need to spam our logs, we just haven't implemented it yet+ return None+ else:+ # this means GH has actually added new actions since September 2020,+ # so it's a bit more cause for alarm+ raise UnexpectedWebhookEventType("GitHub", f"unexpected team action {action}")elif event in list(EVENT_FUNCTION_MAPPER.keys()) or event == 'ping':return eventelif event in IGNORED_EVENTS: