Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/pagerduty: Cleanup unsupported v1 events.
sathwikshetty33721a4cef1b4b
diff --git a/zerver/webhooks/pagerduty/fixtures/acknowledge.json b/zerver/webhooks/pagerduty/fixtures/acknowledge.jsondeleted file mode 100644index 3f9f0589689..00000000000--- a/zerver/webhooks/pagerduty/fixtures/acknowledge.json+++ /dev/null@@ -1,162 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-07T21:09:49Z",- "data": {- "incident": {- "acknowledgers": [- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to": [- {- "at": "2015-02-07T21:08:36Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/PJ9ODL1",- "id": "PJ9ODL1",- "name": "Armooo2",- "type": "user"- }- },- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "created_on": "2015-02-07T21:05:47Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5",- "id": "PO1XIJ5",- "incident_key": "It is on fire",- "incident_number": 1,- "last_status_change_by": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "last_status_change_on": "2015-02-07T21:09:49Z",- "number_of_escalations": 0,- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "acknowledged",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5/log_entries/Q01ZH27LNRIAUB",- "trigger_summary_data": {- "subject": "It is on fire"- },- "trigger_type": "email_trigger"- }- },- "id": "a710cfd0-af0d-11e4-8aca-f23c91739642",- "type": "incident.assign"- },- {- "created_on": "2015-02-07T21:09:49Z",- "data": {- "incident": {- "acknowledgers": [- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to": [- {- "at": "2015-02-07T21:08:36Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/PJ9ODL1",- "id": "PJ9ODL1",- "name": "Armooo2",- "type": "user"- }- },- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "created_on": "2015-02-07T21:05:47Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5",- "id": "PO1XIJ5",- "incident_key": "It is on fire",- "incident_number": 1,- "last_status_change_by": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "last_status_change_on": "2015-02-07T21:09:49Z",- "number_of_escalations": 0,- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "acknowledged",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5/log_entries/Q01ZH27LNRIAUB",- "trigger_summary_data": {- "subject": "It is on fire"- },- "trigger_type": "email_trigger"- }- },- "id": "a7169c30-af0d-11e4-8aca-f23c91739642",- "type": "incident.acknowledge"- }- ]-}diff --git a/zerver/webhooks/pagerduty/fixtures/acknowledge_without_trigger_summary_data.json b/zerver/webhooks/pagerduty/fixtures/acknowledge_without_trigger_summary_data.jsondeleted file mode 100644index 236dc275b97..00000000000--- a/zerver/webhooks/pagerduty/fixtures/acknowledge_without_trigger_summary_data.json+++ /dev/null@@ -1,158 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-07T21:09:49Z",- "data": {- "incident": {- "acknowledgers": [- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to": [- {- "at": "2015-02-07T21:08:36Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/PJ9ODL1",- "id": "PJ9ODL1",- "name": "Armooo2",- "type": "user"- }- },- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "created_on": "2015-02-07T21:05:47Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5",- "id": "PO1XIJ5",- "incident_key": "It is on fire",- "incident_number": 1,- "last_status_change_by": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "last_status_change_on": "2015-02-07T21:09:49Z",- "number_of_escalations": 0,- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "acknowledged",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5/log_entries/Q01ZH27LNRIAUB",- "trigger_summary_data": null,- "trigger_type": "email_trigger"- }- },- "id": "a710cfd0-af0d-11e4-8aca-f23c91739642",- "type": "incident.assign"- },- {- "created_on": "2015-02-07T21:09:49Z",- "data": {- "incident": {- "acknowledgers": [- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to": [- {- "at": "2015-02-07T21:08:36Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/PJ9ODL1",- "id": "PJ9ODL1",- "name": "Armooo2",- "type": "user"- }- },- {- "at": "2015-02-07T21:09:49Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "created_on": "2015-02-07T21:05:47Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5",- "id": "PO1XIJ5",- "incident_key": "It is on fire",- "incident_number": 1,- "last_status_change_by": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "last_status_change_on": "2015-02-07T21:09:49Z",- "number_of_escalations": 0,- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "acknowledged",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5/log_entries/Q01ZH27LNRIAUB",- "trigger_summary_data": null,- "trigger_type": "email_trigger"- }- },- "id": "a7169c30-af0d-11e4-8aca-f23c91739642",- "type": "incident.acknowledge"- }- ]-}diff --git a/zerver/webhooks/pagerduty/fixtures/auto_resolved.json b/zerver/webhooks/pagerduty/fixtures/auto_resolved.jsondeleted file mode 100644index 9ea19129934..00000000000--- a/zerver/webhooks/pagerduty/fixtures/auto_resolved.json+++ /dev/null@@ -1,41 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-07T21:29:42Z",- "data": {- "incident": {- "assigned_to": [],- "assigned_to_user": null,- "created_on": "2015-02-07T21:19:42Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/PX7K9J2",- "id": "PX7K9J2",- "incident_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",- "incident_number": 2,- "last_status_change_by": null,- "last_status_change_on": "2015-02-07T21:29:42Z",- "number_of_escalations": 0,- "resolved_by_user": null,- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "resolved",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/PX7K9J2/log_entries/Q2LOVDWN1FGDPC",- "trigger_summary_data": {- "subject": "new"- },- "trigger_type": "web_trigger"- }- },- "id": "6e0d4b20-af10-11e4-8aca-f23c91739642",- "type": "incident.resolve"- }- ]-}diff --git a/zerver/webhooks/pagerduty/fixtures/mp_fail.json b/zerver/webhooks/pagerduty/fixtures/mp_fail.jsondeleted file mode 100644index 3460d1349c9..00000000000--- a/zerver/webhooks/pagerduty/fixtures/mp_fail.json+++ /dev/null@@ -1,41 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-09T18:31:05Z",- "data": {- "incident": {- "assigned_to": [],- "assigned_to_user": null,- "created_on": "2015-02-09T18:30:06Z",- "escalation_policy": {- "deleted_at": null,- "id": "P4BZUGM",- "name": "MP on-call"- },- "html_url": "https://dropbox.pagerduty.com/incidents/PJKGZF9",- "id": "PJKGZF9",- "incident_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",- "incident_number": 48219,- "last_status_change_by": null,- "last_status_change_on": "2015-02-09T18:31:05Z",- "number_of_escalations": 0,- "resolved_by_user": null,- "service": {- "deleted_at": null,- "html_url": "https://dropbox.pagerduty.com/services/PINP5IV",- "id": "PINP5IV",- "name": "MP API"- },- "status": "resolved",- "trigger_details_html_url": "https://dropbox.pagerduty.com/incidents/PJKGZF9/log_entries/Q1TF6UA8WN4AK8",- "trigger_summary_data": {- "description": "mp_error_block_down_criticalℙƴ"- },- "trigger_type": "trigger_svc_event"- }- },- "id": "cf419f70-b089-11e4-9e4c-f23c91739642",- "type": "incident.resolve"- }- ]-}diff --git a/zerver/webhooks/pagerduty/fixtures/resolved.json b/zerver/webhooks/pagerduty/fixtures/resolved.jsondeleted file mode 100644index 61d88fef613..00000000000--- a/zerver/webhooks/pagerduty/fixtures/resolved.json+++ /dev/null@@ -1,51 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-07T21:31:53Z",- "data": {- "incident": {- "assigned_to": [],- "assigned_to_user": null,- "created_on": "2015-02-07T21:05:47Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5",- "id": "PO1XIJ5",- "incident_key": "It is on fire",- "incident_number": 1,- "last_status_change_by": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "last_status_change_on": "2015-02-07T21:31:53Z",- "number_of_escalations": 0,- "resolved_by_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "resolved",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5/log_entries/Q01ZH27LNRIAUB",- "trigger_summary_data": {- "subject": "It is on fire"- },- "trigger_type": "email_trigger"- }- },- "id": "bc3d9ed0-af10-11e4-947f-22000ad9bf74",- "type": "incident.resolve"- }- ]-}diff --git a/zerver/webhooks/pagerduty/fixtures/trigger.json b/zerver/webhooks/pagerduty/fixtures/trigger.jsondeleted file mode 100644index e74d8e7b43a..00000000000--- a/zerver/webhooks/pagerduty/fixtures/trigger.json+++ /dev/null@@ -1,56 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-07T21:42:52Z",- "data": {- "incident": {- "assigned_to": [- {- "at": "2015-02-07T21:42:52Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason Michalski",- "type": "user"- }- }- ],- "assigned_to_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason Michalski"- },- "created_on": "2015-02-07T21:42:52Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/P140S4Y",- "id": "P140S4Y",- "incident_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",- "incident_number": 3,- "last_status_change_by": null,- "last_status_change_on": "2015-02-07T21:42:52Z",- "number_of_escalations": 0,- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "triggered",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/P140S4Y/log_entries/Q3P8OPKZDJWLKB",- "trigger_summary_data": {- "subject": "foo"- },- "trigger_type": "web_trigger"- }- },- "id": "44df6240-af12-11e4-8e1e-22000ae31361",- "type": "incident.trigger"- }- ]-}diff --git a/zerver/webhooks/pagerduty/fixtures/unacknowledge.json b/zerver/webhooks/pagerduty/fixtures/unacknowledge.jsondeleted file mode 100644index 2ae6b5b6a7e..00000000000--- a/zerver/webhooks/pagerduty/fixtures/unacknowledge.json+++ /dev/null@@ -1,56 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-07T21:53:09Z",- "data": {- "incident": {- "assigned_to": [- {- "at": "2015-02-07T21:42:52Z",- "object": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski",- "type": "user"- }- }- ],- "assigned_to_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "created_on": "2015-02-07T21:42:52Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/P140S4Y",- "id": "P140S4Y",- "incident_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",- "incident_number": 3,- "last_status_change_by": null,- "last_status_change_on": "2015-02-07T21:53:09Z",- "number_of_escalations": 0,- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "triggered",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/P140S4Y/log_entries/Q3P8OPKZDJWLKB",- "trigger_summary_data": {- "subject": "foo"- },- "trigger_type": "web_trigger"- }- },- "id": "b4695980-af13-11e4-8a3a-12313f0a2181",- "type": "incident.unacknowledge"- }- ]-}diff --git a/zerver/webhooks/pagerduty/fixtures/unsupported_v1.json b/zerver/webhooks/pagerduty/fixtures/unsupported_v1.jsondeleted file mode 100644index d391dba3d68..00000000000--- a/zerver/webhooks/pagerduty/fixtures/unsupported_v1.json+++ /dev/null@@ -1,51 +0,0 @@-{- "messages": [- {- "created_on": "2015-02-07T21:31:53Z",- "data": {- "incident": {- "assigned_to": [],- "assigned_to_user": null,- "created_on": "2015-02-07T21:05:47Z",- "escalation_policy": {- "deleted_at": null,- "id": "PUIGL4T",- "name": "Default"- },- "html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5",- "id": "PO1XIJ5",- "incident_key": "It is on fire",- "incident_number": 1,- "last_status_change_by": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "last_status_change_on": "2015-02-07T21:31:53Z",- "number_of_escalations": 0,- "resolved_by_user": {- "email": "[email protected]",- "html_url": "https://zulip-test.pagerduty.com/users/POBCFRJ",- "id": "POBCFRJ",- "name": "Jason MIchalski"- },- "service": {- "deleted_at": null,- "html_url": "https://zulip-test.pagerduty.com/services/PIL5CUQ",- "id": "PIL5CUQ",- "name": "Test service"- },- "status": "resolved",- "trigger_details_html_url": "https://zulip-test.pagerduty.com/incidents/PO1XIJ5/log_entries/Q01ZH27LNRIAUB",- "trigger_summary_data": {- "subject": "It is on fire"- },- "trigger_type": "email_trigger"- }- },- "id": "bc3d9ed0-af10-11e4-947f-22000ad9bf74",- "type": "incident.unsupported"- }- ]-}diff --git a/zerver/webhooks/pagerduty/tests.py b/zerver/webhooks/pagerduty/tests.pyindex cc6982ad29b..3ac28a9cdc0 100644--- a/zerver/webhooks/pagerduty/tests.py+++ b/zerver/webhooks/pagerduty/tests.py@@ -2,10 +2,6 @@ from zerver.lib.test_classes import WebhookTestCaseclass PagerDutyHookTests(WebhookTestCase):- def test_trigger(self) -> None:- expected_message = "Incident [3](https://zulip-test.pagerduty.com/incidents/P140S4Y) triggered by [Test service](https://zulip-test.pagerduty.com/services/PIL5CUQ) (assigned to [armooo](https://zulip-test.pagerduty.com/users/POBCFRJ)).\n\n``` quote\nfoo\n```"- self.check_webhook("trigger", "Incident 3", expected_message)-def test_trigger_v2(self) -> None:expected_message = "Incident [33](https://webdemo.pagerduty.com/incidents/PRORDTY) triggered by [Production XDB Cluster](https://webdemo.pagerduty.com/services/PN49J75) (assigned to [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV)).\n\n``` quote\nMy new incident\n```"self.check_webhook("trigger_v2", "Incident 33", expected_message)@@ -18,18 +14,10 @@ class PagerDutyHookTests(WebhookTestCase):expected_message = "Incident [33](https://webdemo.pagerduty.com/incidents/PRORDTY) triggered by [Production XDB Cluster](https://webdemo.pagerduty.com/services/PN49J75) (assigned to nobody).\n\n``` quote\nMy new incident\n```"self.check_webhook("trigger_without_assignee_v2", "Incident 33", expected_message)- def test_unacknowledge(self) -> None:- expected_message = "Incident [3](https://zulip-test.pagerduty.com/incidents/P140S4Y) unacknowledged by [Test service](https://zulip-test.pagerduty.com/services/PIL5CUQ) (assigned to [armooo](https://zulip-test.pagerduty.com/users/POBCFRJ)).\n\n``` quote\nfoo\n```"- self.check_webhook("unacknowledge", "Incident 3", expected_message)-def test_unacknowledged_v3(self) -> None:expected_message = "Incident [Test Incident (#10)](https://pig208.pagerduty.com/incidents/PQ1K5C8) unacknowledged by [pig208](https://pig208.pagerduty.com/services/PA2P440) (assigned to [PIG 208](https://pig208.pagerduty.com/users/PJ0LVEB))."self.check_webhook("unacknowledged_v3", "Incident Test Incident (#10)", expected_message)- def test_resolved(self) -> None:- expected_message = "Incident [1](https://zulip-test.pagerduty.com/incidents/PO1XIJ5) resolved by [armooo](https://zulip-test.pagerduty.com/users/POBCFRJ).\n\n``` quote\nIt is on fire\n```"- self.check_webhook("resolved", "Incident 1", expected_message)-def test_resolved_v2(self) -> None:expected_message = "Incident [33](https://webdemo.pagerduty.com/incidents/PRORDTY) resolved by [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV).\n\n``` quote\nMy new incident\n```"self.check_webhook("resolve_v2", "Incident 33", expected_message)@@ -38,20 +26,6 @@ class PagerDutyHookTests(WebhookTestCase):expected_message = "Incident [Test Incident (#6)](https://pig208.pagerduty.com/incidents/PCPZE64) resolved by [PIG 208](https://pig208.pagerduty.com/users/PJ0LVEB)."self.check_webhook("resolved_v3", "Incident Test Incident (#6)", expected_message)- def test_auto_resolved(self) -> None:- expected_message = "Incident [2](https://zulip-test.pagerduty.com/incidents/PX7K9J2) resolved.\n\n``` quote\nnew\n```"- self.check_webhook("auto_resolved", "Incident 2", expected_message)-- def test_acknowledge(self) -> None:- expected_message = "Incident [1](https://zulip-test.pagerduty.com/incidents/PO1XIJ5) acknowledged by [armooo](https://zulip-test.pagerduty.com/users/POBCFRJ).\n\n``` quote\nIt is on fire\n```"- self.check_webhook("acknowledge", "Incident 1", expected_message)-- def test_acknowledge_without_trigger_summary_data(self) -> None:- expected_message = "Incident [1](https://zulip-test.pagerduty.com/incidents/PO1XIJ5) acknowledged by [armooo](https://zulip-test.pagerduty.com/users/POBCFRJ).\n\n``` quote\n\n```"- self.check_webhook(- "acknowledge_without_trigger_summary_data", "Incident 1", expected_message- )-def test_acknowledged_v3(self) -> None:expected_message = "Incident [Test Incident (#10)](https://pig208.pagerduty.com/incidents/PQ1K5C8) acknowledged by [PIG 208](https://pig208.pagerduty.com/users/PJ0LVEB)."self.check_webhook("acknowledged_v3", "Incident Test Incident (#10)", expected_message)@@ -68,12 +42,8 @@ class PagerDutyHookTests(WebhookTestCase):expected_message = "Incident [Test Incident (#3)](https://pig208.pagerduty.com/incidents/PIQUG8X) reassigned to [Test User](https://pig208.pagerduty.com/users/PI9DT01)."self.check_webhook("reassigned_v3", "Incident Test Incident (#3)", expected_message)- def test_no_subject(self) -> None:- expected_message = "Incident [48219](https://dropbox.pagerduty.com/incidents/PJKGZF9) resolved.\n\n``` quote\nmp_error_block_down_critical\u2119\u01b4\n```"- self.check_webhook("mp_fail", "Incident 48219", expected_message)-def test_unsupported_webhook_event(self) -> None:- for version in range(1, 4):+ for version in range(2, 4):payload = self.get_body(f"unsupported_v{version}")result = self.client_post(self.url, payload, content_type="application/json")self.assert_json_success(result)diff --git a/zerver/webhooks/pagerduty/view.py b/zerver/webhooks/pagerduty/view.pyindex 0c08d80c07c..ac36894367f 100644--- a/zerver/webhooks/pagerduty/view.py+++ b/zerver/webhooks/pagerduty/view.py@@ -1,4 +1,3 @@-from email.headerregistry import Addressfrom typing import TypeAliasfrom django.http import HttpRequest, HttpResponse@@ -13,16 +12,6 @@ from zerver.models import UserProfileFormatDictType: TypeAlias = dict[str, str | int]-PAGER_DUTY_EVENT_NAMES = {- "incident.trigger": "triggered",- "incident.acknowledge": "acknowledged",- "incident.unacknowledge": "unacknowledged",- "incident.resolve": "resolved",- "incident.assign": "assigned",- "incident.escalate": "escalated",- "incident.delegate": "delineated",-}-PAGER_DUTY_EVENT_NAMES_V2 = {"incident.trigger": "triggered","incident.acknowledge": "acknowledged",@@ -83,52 +72,6 @@ Incident [{incident_num_title}]({incident_url}) resolved.""".strip()-def build_pagerduty_formatdict(message: WildValue) -> FormatDictType:- format_dict: FormatDictType = {}- format_dict["action"] = PAGER_DUTY_EVENT_NAMES[message["type"].tame(check_string)]-- format_dict["incident_id"] = message["data"]["incident"]["id"].tame(check_string)- format_dict["incident_num_title"] = message["data"]["incident"]["incident_number"].tame(- check_int- )- format_dict["incident_url"] = message["data"]["incident"]["html_url"].tame(check_string)-- format_dict["service_name"] = message["data"]["incident"]["service"]["name"].tame(check_string)- format_dict["service_url"] = message["data"]["incident"]["service"]["html_url"].tame(- check_string- )-- if message["data"]["incident"].get("assigned_to_user"):- assigned_to_user = message["data"]["incident"]["assigned_to_user"]- format_dict["assignee_info"] = AGENT_TEMPLATE.format(- username=Address(addr_spec=assigned_to_user["email"].tame(check_string)).username,- url=assigned_to_user["html_url"].tame(check_string),- )- else:- format_dict["assignee_info"] = "nobody"-- if message["data"]["incident"].get("resolved_by_user"):- resolved_by_user = message["data"]["incident"]["resolved_by_user"]- format_dict["agent_info"] = AGENT_TEMPLATE.format(- username=Address(addr_spec=resolved_by_user["email"].tame(check_string)).username,- url=resolved_by_user["html_url"].tame(check_string),- )-- trigger_message = []- trigger_summary_data = message["data"]["incident"].get("trigger_summary_data")- if trigger_summary_data:- trigger_subject = trigger_summary_data.get("subject", "").tame(check_string)- if trigger_subject:- trigger_message.append(trigger_subject)-- trigger_description = trigger_summary_data.get("description", "").tame(check_string)- if trigger_description:- trigger_message.append(trigger_description)-- format_dict["trigger_message"] = TRIGGER_MESSAGE.format(message="\n".join(trigger_message))- return format_dict--def build_pagerduty_formatdict_v2(message: WildValue) -> FormatDictType:format_dict: FormatDictType = {}format_dict["action"] = PAGER_DUTY_EVENT_NAMES_V2[message["event"].tame(check_string)]@@ -217,7 +160,7 @@ def send_formatted_pagerduty(if "agent_info" in format_dict:template = INCIDENT_RESOLVED_WITH_AGENTelse:- template = INCIDENT_RESOLVED+ template = INCIDENT_RESOLVED # nocoverageelif message_type in ("incident.assign", "incident.reassigned"):template = INCIDENT_ASSIGNEDelse:@@ -239,28 +182,9 @@ def api_pagerduty_webhook() -> HttpResponse:messages = payload.get("messages")if messages:- for message in messages:- message_type = message.get("type").tame(check_none_or(check_string))-- # If the message has no "type" key, then this payload came from a- # Pagerduty Webhook V2.- if message_type is None:- break-- if message_type not in PAGER_DUTY_EVENT_NAMES:- raise UnsupportedWebhookEventTypeError(message_type)-- format_dict = build_pagerduty_formatdict(message)- send_formatted_pagerduty(request, user_profile, message_type, format_dict)-for message in messages:message_event = message.get("event").tame(check_none_or(check_string))- # If the message has no "event" key, then this payload came from a- # Pagerduty Webhook V1.- if message_event is None:- break-if message_event not in PAGER_DUTY_EVENT_NAMES_V2:raise UnsupportedWebhookEventTypeError(message_event)