Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

github: Handle ping events from GitHub Sponsors webhooks.

Aman Agrawal573cd1c2013b
diff --git a/zerver/webhooks/github/fixtures/ping__sponsors.json b/zerver/webhooks/github/fixtures/ping__sponsors.json
new file mode 100644
index 00000000000..12878c00417
--- /dev/null
+++ b/zerver/webhooks/github/fixtures/ping__sponsors.json
@@ -0,0 +1,30 @@
+{
+ "zen": "Avoid administrative distraction.",
+ "hook_id": 624672630,
+ "hook": {
+ "type": "SponsorsListing",
+ "id": 624672630,
+ "name": "web",
+ "active": true,
+ "events": [
+ "sponsorship"
+ ],
+ "config": {
+ "content_type": "json",
+ "insecure_ssl": "0",
+ "url": "https://example.com/hook"
+ },
+ "updated_at": "2026-05-16T00:00:00Z",
+ "created_at": "2026-05-16T00:00:00Z"
+ },
+ "sender": {
+ "login": "marcphilipp",
+ "id": 111111,
+ "avatar_url": "https://avatars.githubusercontent.com/u/111111?v=4",
+ "gravatar_id": "",
+ "url": "https://api.github.com/users/marcphilipp",
+ "html_url": "https://github.com/marcphilipp",
+ "type": "User",
+ "site_admin": false
+ }
+}
diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py
index 171658749c8..5f5909e4419 100644
--- a/zerver/webhooks/github/tests.py
+++ b/zerver/webhooks/github/tests.py
@@ -906,3 +906,7 @@ class GitHubSponsorsHookTests(WebhookTestCase):
TOPIC_SPONSORS,
expected_message,
)
+
+ def test_ping_message(self) -> None:
+ expected_message = "GitHub webhook has been successfully configured by marcphilipp."
+ self.check_webhook("ping__sponsors", TOPIC_SPONSORS, expected_message)
diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py
index 17fdc37f002..c1a13b5ad0d 100644
--- a/zerver/webhooks/github/view.py
+++ b/zerver/webhooks/github/view.py
@@ -1078,8 +1078,16 @@ def get_topic_based_on_type(payload: WildValue, event: str) -> str:
branch="wiki pages",
)
elif event == "ping":
- if not payload.get("repository"):
+ if "repository" in payload:
+ return get_repository_name(payload)
+ if "organization" in payload:
return get_organization_name(payload)
+ # GitHub Sponsors webhook pings include neither "repository" nor
+ # "organization"; group them under the topic SPONSORS_EVENT_TYPES use.
+ hook_type = payload["hook"]["type"].tame(check_string)
+ if hook_type == "SponsorsListing":
+ return "sponsors"
+ raise UnsupportedWebhookEventTypeError(f"ping:{hook_type}")
elif event == "check_run":
return f"{get_repository_name(payload)} / checks"
elif event.startswith("discussion"):