Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/github: Add support for repository_advisory events.
Niloth P9082045be057
diff --git a/zerver/webhooks/github/fixtures/repository_advisory__published.json b/zerver/webhooks/github/fixtures/repository_advisory__published.jsonnew file mode 100644index 00000000000..a08e61b0f7a--- /dev/null+++ b/zerver/webhooks/github/fixtures/repository_advisory__published.json@@ -0,0 +1,201 @@+{+ "action": "published",+ "repository_advisory": {+ "ghsa_id": "GHSA-vw49-7xw6-7ghw",+ "cve_id": null,+ "url": "https://api.github.com/repos/Niloth-p/test-repo/security-advisories/GHSA-vw49-7xw6-7ghw",+ "html_url": "https://github.com/Niloth-p/test-repo/security/advisories/GHSA-vw49-7xw6-7ghw",+ "summary": "test",+ "description": "### Impact\r\ntest\r\n\r\n### Patches\r\ntest\r\n\r\n",+ "severity": "low",+ "author": null,+ "publisher": {+ "login": "Niloth-p",+ "id": 24371319,+ "node_id": "MDQ6VXNlcjI0MzcxMzE5",+ "avatar_url": "https://avatars.githubusercontent.com/u/24371319?v=4",+ "gravatar_id": "",+ "url": "https://api.github.com/users/Niloth-p",+ "html_url": "https://github.com/Niloth-p",+ "followers_url": "https://api.github.com/users/Niloth-p/followers",+ "following_url": "https://api.github.com/users/Niloth-p/following{/other_user}",+ "gists_url": "https://api.github.com/users/Niloth-p/gists{/gist_id}",+ "starred_url": "https://api.github.com/users/Niloth-p/starred{/owner}{/repo}",+ "subscriptions_url": "https://api.github.com/users/Niloth-p/subscriptions",+ "organizations_url": "https://api.github.com/users/Niloth-p/orgs",+ "repos_url": "https://api.github.com/users/Niloth-p/repos",+ "events_url": "https://api.github.com/users/Niloth-p/events{/privacy}",+ "received_events_url": "https://api.github.com/users/Niloth-p/received_events",+ "type": "User",+ "user_view_type": "public",+ "site_admin": false+ },+ "identifiers": [+ {+ "value": "GHSA-vw49-7xw6-7ghw",+ "type": "GHSA"+ }+ ],+ "state": "published",+ "created_at": null,+ "updated_at": "2026-02-04T22:45:54Z",+ "published_at": "2026-02-04T22:45:54Z",+ "closed_at": null,+ "withdrawn_at": null,+ "submission": null,+ "vulnerabilities": [+ {+ "package": {+ "ecosystem": "",+ "name": ""+ },+ "vulnerable_version_range": "0.0.1",+ "patched_versions": "",+ "vulnerable_functions": []+ }+ ],+ "cvss_severities": {+ "cvss_v3": {+ "vector_string": null,+ "score": null+ },+ "cvss_v4": {+ "vector_string": null,+ "score": null+ }+ },+ "cwes": [],+ "cwe_ids": [],+ "credits": [],+ "credits_detailed": [],+ "collaborating_users": null,+ "collaborating_teams": null,+ "private_fork": null,+ "cvss": {+ "vector_string": null,+ "score": null+ }+ },+ "repository": {+ "id": 1150116735,+ "node_id": "R_kgDORI1jfw",+ "name": "test-repo",+ "full_name": "Niloth-p/test-repo",+ "private": false,+ "owner": {+ "login": "Niloth-p",+ "id": 24371319,+ "node_id": "MDQ6VXNlcjI0MzcxMzE5",+ "avatar_url": "https://avatars.githubusercontent.com/u/24371319?v=4",+ "gravatar_id": "",+ "url": "https://api.github.com/users/Niloth-p",+ "html_url": "https://github.com/Niloth-p",+ "followers_url": "https://api.github.com/users/Niloth-p/followers",+ "following_url": "https://api.github.com/users/Niloth-p/following{/other_user}",+ "gists_url": "https://api.github.com/users/Niloth-p/gists{/gist_id}",+ "starred_url": "https://api.github.com/users/Niloth-p/starred{/owner}{/repo}",+ "subscriptions_url": "https://api.github.com/users/Niloth-p/subscriptions",+ "organizations_url": "https://api.github.com/users/Niloth-p/orgs",+ "repos_url": "https://api.github.com/users/Niloth-p/repos",+ "events_url": "https://api.github.com/users/Niloth-p/events{/privacy}",+ "received_events_url": "https://api.github.com/users/Niloth-p/received_events",+ "type": "User",+ "user_view_type": "public",+ "site_admin": false+ },+ "html_url": "https://github.com/Niloth-p/test-repo",+ "description": null,+ "fork": false,+ "url": "https://api.github.com/repos/Niloth-p/test-repo",+ "forks_url": "https://api.github.com/repos/Niloth-p/test-repo/forks",+ "keys_url": "https://api.github.com/repos/Niloth-p/test-repo/keys{/key_id}",+ "collaborators_url": "https://api.github.com/repos/Niloth-p/test-repo/collaborators{/collaborator}",+ "teams_url": "https://api.github.com/repos/Niloth-p/test-repo/teams",+ "hooks_url": "https://api.github.com/repos/Niloth-p/test-repo/hooks",+ "issue_events_url": "https://api.github.com/repos/Niloth-p/test-repo/issues/events{/number}",+ "events_url": "https://api.github.com/repos/Niloth-p/test-repo/events",+ "assignees_url": "https://api.github.com/repos/Niloth-p/test-repo/assignees{/user}",+ "branches_url": "https://api.github.com/repos/Niloth-p/test-repo/branches{/branch}",+ "tags_url": "https://api.github.com/repos/Niloth-p/test-repo/tags",+ "blobs_url": "https://api.github.com/repos/Niloth-p/test-repo/git/blobs{/sha}",+ "git_tags_url": "https://api.github.com/repos/Niloth-p/test-repo/git/tags{/sha}",+ "git_refs_url": "https://api.github.com/repos/Niloth-p/test-repo/git/refs{/sha}",+ "trees_url": "https://api.github.com/repos/Niloth-p/test-repo/git/trees{/sha}",+ "statuses_url": "https://api.github.com/repos/Niloth-p/test-repo/statuses/{sha}",+ "languages_url": "https://api.github.com/repos/Niloth-p/test-repo/languages",+ "stargazers_url": "https://api.github.com/repos/Niloth-p/test-repo/stargazers",+ "contributors_url": "https://api.github.com/repos/Niloth-p/test-repo/contributors",+ "subscribers_url": "https://api.github.com/repos/Niloth-p/test-repo/subscribers",+ "subscription_url": "https://api.github.com/repos/Niloth-p/test-repo/subscription",+ "commits_url": "https://api.github.com/repos/Niloth-p/test-repo/commits{/sha}",+ "git_commits_url": "https://api.github.com/repos/Niloth-p/test-repo/git/commits{/sha}",+ "comments_url": "https://api.github.com/repos/Niloth-p/test-repo/comments{/number}",+ "issue_comment_url": "https://api.github.com/repos/Niloth-p/test-repo/issues/comments{/number}",+ "contents_url": "https://api.github.com/repos/Niloth-p/test-repo/contents/{+path}",+ "compare_url": "https://api.github.com/repos/Niloth-p/test-repo/compare/{base}...{head}",+ "merges_url": "https://api.github.com/repos/Niloth-p/test-repo/merges",+ "archive_url": "https://api.github.com/repos/Niloth-p/test-repo/{archive_format}{/ref}",+ "downloads_url": "https://api.github.com/repos/Niloth-p/test-repo/downloads",+ "issues_url": "https://api.github.com/repos/Niloth-p/test-repo/issues{/number}",+ "pulls_url": "https://api.github.com/repos/Niloth-p/test-repo/pulls{/number}",+ "milestones_url": "https://api.github.com/repos/Niloth-p/test-repo/milestones{/number}",+ "notifications_url": "https://api.github.com/repos/Niloth-p/test-repo/notifications{?since,all,participating}",+ "labels_url": "https://api.github.com/repos/Niloth-p/test-repo/labels{/name}",+ "releases_url": "https://api.github.com/repos/Niloth-p/test-repo/releases{/id}",+ "deployments_url": "https://api.github.com/repos/Niloth-p/test-repo/deployments",+ "created_at": "2026-02-04T22:39:57Z",+ "updated_at": "2026-02-04T22:40:01Z",+ "pushed_at": "2026-02-04T22:39:58Z",+ "git_url": "git://github.com/Niloth-p/test-repo.git",+ "ssh_url": "[email protected]:Niloth-p/test-repo.git",+ "clone_url": "https://github.com/Niloth-p/test-repo.git",+ "svn_url": "https://github.com/Niloth-p/test-repo",+ "homepage": null,+ "size": 0,+ "stargazers_count": 0,+ "watchers_count": 0,+ "language": null,+ "has_issues": true,+ "has_projects": true,+ "has_downloads": true,+ "has_wiki": true,+ "has_pages": false,+ "has_discussions": false,+ "forks_count": 0,+ "mirror_url": null,+ "archived": false,+ "disabled": false,+ "open_issues_count": 0,+ "license": null,+ "allow_forking": true,+ "is_template": false,+ "web_commit_signoff_required": false,+ "topics": [],+ "visibility": "public",+ "forks": 0,+ "open_issues": 0,+ "watchers": 0,+ "default_branch": "main"+ },+ "sender": {+ "login": "Niloth-p",+ "id": 24371319,+ "node_id": "MDQ6VXNlcjI0MzcxMzE5",+ "avatar_url": "https://avatars.githubusercontent.com/u/24371319?v=4",+ "gravatar_id": "",+ "url": "https://api.github.com/users/Niloth-p",+ "html_url": "https://github.com/Niloth-p",+ "followers_url": "https://api.github.com/users/Niloth-p/followers",+ "following_url": "https://api.github.com/users/Niloth-p/following{/other_user}",+ "gists_url": "https://api.github.com/users/Niloth-p/gists{/gist_id}",+ "starred_url": "https://api.github.com/users/Niloth-p/starred{/owner}{/repo}",+ "subscriptions_url": "https://api.github.com/users/Niloth-p/subscriptions",+ "organizations_url": "https://api.github.com/users/Niloth-p/orgs",+ "repos_url": "https://api.github.com/users/Niloth-p/repos",+ "events_url": "https://api.github.com/users/Niloth-p/events{/privacy}",+ "received_events_url": "https://api.github.com/users/Niloth-p/received_events",+ "type": "User",+ "user_view_type": "public",+ "site_admin": false+ }+}diff --git a/zerver/webhooks/github/fixtures/repository_advisory__reported.json b/zerver/webhooks/github/fixtures/repository_advisory__reported.jsonnew file mode 100644index 00000000000..a70f99b05bb--- /dev/null+++ b/zerver/webhooks/github/fixtures/repository_advisory__reported.json@@ -0,0 +1,181 @@+{+ "action": "reported",+ "repository_advisory": {+ "ghsa_id": "GHSA-7jw9-r89j-6gg9",+ "cve_id": null,+ "url": "https://api.github.com/repos/Niloth-p/test-repo/security-advisories/GHSA-7jw9-r89j-6gg9",+ "html_url": "https://github.com/Niloth-p/test-repo/security/advisories/GHSA-7jw9-r89j-6gg9",+ "summary": "test report",+ "description": "### Summary\r\ntest\r\n\r\n",+ "severity": "low",+ "author": null,+ "publisher": null,+ "identifiers": [+ {+ "value": "GHSA-7jw9-r89j-6gg9",+ "type": "GHSA"+ }+ ],+ "state": "triage",+ "created_at": null,+ "updated_at": "2026-02-04T22:51:12Z",+ "published_at": null,+ "closed_at": null,+ "withdrawn_at": null,+ "submission": null,+ "vulnerabilities": [+ {+ "package": {+ "ecosystem": "",+ "name": ""+ },+ "vulnerable_version_range": "0.0.1",+ "patched_versions": "",+ "vulnerable_functions": []+ }+ ],+ "cvss_severities": {+ "cvss_v3": {+ "vector_string": null,+ "score": null+ },+ "cvss_v4": {+ "vector_string": null,+ "score": null+ }+ },+ "cwes": [],+ "cwe_ids": [],+ "credits": [],+ "credits_detailed": [],+ "collaborating_users": null,+ "collaborating_teams": null,+ "private_fork": null,+ "cvss": {+ "vector_string": null,+ "score": null+ }+ },+ "repository": {+ "id": 1150106735,+ "node_id": "R_khDORI1jfw",+ "name": "test-repo",+ "full_name": "Niloth-p/test-repo",+ "private": false,+ "owner": {+ "login": "Niloth-p",+ "id": 24371319,+ "node_id": "MDQ6VXNlcjIwMzE1MzA4",+ "avatar_url": "https://avatars.githubusercontent.com/u/24371319?v=4",+ "gravatar_id": "",+ "url": "https://api.github.com/users/Niloth-p",+ "html_url": "https://github.com/Niloth-p",+ "followers_url": "https://api.github.com/users/Niloth-p/followers",+ "following_url": "https://api.github.com/users/Niloth-p/following{/other_user}",+ "gists_url": "https://api.github.com/users/Niloth-p/gists{/gist_id}",+ "starred_url": "https://api.github.com/users/Niloth-p/starred{/owner}{/repo}",+ "subscriptions_url": "https://api.github.com/users/Niloth-p/subscriptions",+ "organizations_url": "https://api.github.com/users/Niloth-p/orgs",+ "repos_url": "https://api.github.com/users/Niloth-p/repos",+ "events_url": "https://api.github.com/users/Niloth-p/events{/privacy}",+ "received_events_url": "https://api.github.com/users/Niloth-p/received_events",+ "type": "User",+ "user_view_type": "public",+ "site_admin": false+ },+ "html_url": "https://github.com/Niloth-p/test-repo",+ "description": null,+ "fork": false,+ "url": "https://api.github.com/repos/Niloth-p/test-repo",+ "forks_url": "https://api.github.com/repos/Niloth-p/test-repo/forks",+ "keys_url": "https://api.github.com/repos/Niloth-p/test-repo/keys{/key_id}",+ "collaborators_url": "https://api.github.com/repos/Niloth-p/test-repo/collaborators{/collaborator}",+ "teams_url": "https://api.github.com/repos/Niloth-p/test-repo/teams",+ "hooks_url": "https://api.github.com/repos/Niloth-p/test-repo/hooks",+ "issue_events_url": "https://api.github.com/repos/Niloth-p/test-repo/issues/events{/number}",+ "events_url": "https://api.github.com/repos/Niloth-p/test-repo/events",+ "assignees_url": "https://api.github.com/repos/Niloth-p/test-repo/assignees{/user}",+ "branches_url": "https://api.github.com/repos/Niloth-p/test-repo/branches{/branch}",+ "tags_url": "https://api.github.com/repos/Niloth-p/test-repo/tags",+ "blobs_url": "https://api.github.com/repos/Niloth-p/test-repo/git/blobs{/sha}",+ "git_tags_url": "https://api.github.com/repos/Niloth-p/test-repo/git/tags{/sha}",+ "git_refs_url": "https://api.github.com/repos/Niloth-p/test-repo/git/refs{/sha}",+ "trees_url": "https://api.github.com/repos/Niloth-p/test-repo/git/trees{/sha}",+ "statuses_url": "https://api.github.com/repos/Niloth-p/test-repo/statuses/{sha}",+ "languages_url": "https://api.github.com/repos/Niloth-p/test-repo/languages",+ "stargazers_url": "https://api.github.com/repos/Niloth-p/test-repo/stargazers",+ "contributors_url": "https://api.github.com/repos/Niloth-p/test-repo/contributors",+ "subscribers_url": "https://api.github.com/repos/Niloth-p/test-repo/subscribers",+ "subscription_url": "https://api.github.com/repos/Niloth-p/test-repo/subscription",+ "commits_url": "https://api.github.com/repos/Niloth-p/test-repo/commits{/sha}",+ "git_commits_url": "https://api.github.com/repos/Niloth-p/test-repo/git/commits{/sha}",+ "comments_url": "https://api.github.com/repos/Niloth-p/test-repo/comments{/number}",+ "issue_comment_url": "https://api.github.com/repos/Niloth-p/test-repo/issues/comments{/number}",+ "contents_url": "https://api.github.com/repos/Niloth-p/test-repo/contents/{+path}",+ "compare_url": "https://api.github.com/repos/Niloth-p/test-repo/compare/{base}...{head}",+ "merges_url": "https://api.github.com/repos/Niloth-p/test-repo/merges",+ "archive_url": "https://api.github.com/repos/Niloth-p/test-repo/{archive_format}{/ref}",+ "downloads_url": "https://api.github.com/repos/Niloth-p/test-repo/downloads",+ "issues_url": "https://api.github.com/repos/Niloth-p/test-repo/issues{/number}",+ "pulls_url": "https://api.github.com/repos/Niloth-p/test-repo/pulls{/number}",+ "milestones_url": "https://api.github.com/repos/Niloth-p/test-repo/milestones{/number}",+ "notifications_url": "https://api.github.com/repos/Niloth-p/test-repo/notifications{?since,all,participating}",+ "labels_url": "https://api.github.com/repos/Niloth-p/test-repo/labels{/name}",+ "releases_url": "https://api.github.com/repos/Niloth-p/test-repo/releases{/id}",+ "deployments_url": "https://api.github.com/repos/Niloth-p/test-repo/deployments",+ "created_at": "2026-02-04T22:39:57Z",+ "updated_at": "2026-02-04T22:40:01Z",+ "pushed_at": "2026-02-04T22:39:58Z",+ "git_url": "git://github.com/Niloth-p/test-repo.git",+ "ssh_url": "[email protected]:Niloth-p/test-repo.git",+ "clone_url": "https://github.com/Niloth-p/test-repo.git",+ "svn_url": "https://github.com/Niloth-p/test-repo",+ "homepage": null,+ "size": 0,+ "stargazers_count": 0,+ "watchers_count": 0,+ "language": null,+ "has_issues": true,+ "has_projects": true,+ "has_downloads": true,+ "has_wiki": true,+ "has_pages": false,+ "has_discussions": false,+ "forks_count": 0,+ "mirror_url": null,+ "archived": false,+ "disabled": false,+ "open_issues_count": 0,+ "license": null,+ "allow_forking": true,+ "is_template": false,+ "web_commit_signoff_required": false,+ "topics": [],+ "visibility": "public",+ "forks": 0,+ "open_issues": 0,+ "watchers": 0,+ "default_branch": "main"+ },+ "sender": {+ "login": "JohnDoe",+ "id": 130631087,+ "node_id": "U_kgEODFGliw",+ "avatar_url": "https://avatars.githubusercontent.com/u/130631087?v=4",+ "gravatar_id": "",+ "url": "https://api.github.com/users/JohnDoe",+ "html_url": "https://github.com/JohnDoe",+ "followers_url": "https://api.github.com/users/JohnDoe/followers",+ "following_url": "https://api.github.com/users/JohnDoe/following{/other_user}",+ "gists_url": "https://api.github.com/users/JohnDoe/gists{/gist_id}",+ "starred_url": "https://api.github.com/users/JohnDoe/starred{/owner}{/repo}",+ "subscriptions_url": "https://api.github.com/users/JohnDoe/subscriptions",+ "organizations_url": "https://api.github.com/users/JohnDoe/orgs",+ "repos_url": "https://api.github.com/users/JohnDoe/repos",+ "events_url": "https://api.github.com/users/JohnDoe/events{/privacy}",+ "received_events_url": "https://api.github.com/users/JohnDoe/received_events",+ "type": "User",+ "user_view_type": "public",+ "site_admin": false+ }+}diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.pyindex 37b659127b2..fc508191a35 100644--- a/zerver/webhooks/github/tests.py+++ b/zerver/webhooks/github/tests.py@@ -339,6 +339,16 @@ class GitHubWebhookTest(WebhookTestCase):expected_message = "baxterthehacker starred the repository [baxterthehacker/public-repo](https://github.com/baxterthehacker/public-repo)."self.check_webhook("watch__repository", TOPIC_REPO, expected_message)+ def test_repository_advisory_reported(self) -> None:+ expected_topic_name = "test-repo"+ expected_message = "JohnDoe reported [GHSA-7jw9-r89j-6gg9](https://github.com/Niloth-p/test-repo/security/advisories/GHSA-7jw9-r89j-6gg9) in Niloth-p/test-repo: test report\n\n```quote\n### Summary\r\ntest\r\n\r\n\n```"+ self.check_webhook("repository_advisory__reported", expected_topic_name, expected_message)++ def test_repository_advisory_published(self) -> None:+ expected_topic_name = "test-repo"+ expected_message = "Niloth-p published [GHSA-vw49-7xw6-7ghw](https://github.com/Niloth-p/test-repo/security/advisories/GHSA-vw49-7xw6-7ghw)"+ self.check_webhook("repository_advisory__published", expected_topic_name, expected_message)+def test_repository_msg(self) -> None:expected_message = "baxterthehacker created the repository [baxterandthehackers/public-repo](https://github.com/baxterandthehackers/public-repo)."self.check_webhook("repository", TOPIC_REPO, expected_message)diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.pyindex ad9b8ac4173..29ecfcb5907 100644--- a/zerver/webhooks/github/view.py+++ b/zerver/webhooks/github/view.py@@ -467,6 +467,26 @@ def get_watch_body(helper: Helper) -> str:)+def get_repository_advisory_body(helper: Helper) -> str:+ payload = helper.payload+ action = payload["action"].tame(check_string)+ if action == "reported":+ return "{} reported [{}]({}) in {}: {}\n\n```quote\n{}\n```".format(+ get_sender_name(helper),+ payload["repository_advisory"]["ghsa_id"].tame(check_string),+ payload["repository_advisory"]["html_url"].tame(check_string),+ get_repository_full_name(payload),+ payload["repository_advisory"]["summary"].tame(check_string),+ payload["repository_advisory"]["description"].tame(check_string),+ )+ else:+ return "{} published [{}]({})".format(+ get_sender_name(helper),+ payload["repository_advisory"]["ghsa_id"].tame(check_string),+ payload["repository_advisory"]["html_url"].tame(check_string),+ )++def get_repository_body(helper: Helper) -> str:payload = helper.payloadreturn "{} {} the repository [{}]({}).".format(@@ -1049,6 +1069,7 @@ EVENT_FUNCTION_MAPPER: dict[str, Callable[[Helper], str]] = {"push_commits": get_push_commits_body,"push_tags": get_push_tags_body,"release": get_release_body,+ "repository_advisory": get_repository_advisory_body,"repository": get_repository_body,"star": get_star_body,"status": get_status_body,