Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/pagerduty: Improve topic and message content for v2 events.
sathwikshetty330a1eaf7df02b
diff --git a/static/images/integrations/pagerduty/001.png b/static/images/integrations/pagerduty/001.pngindex 9225090795e..f9b4a723b31 100644Binary files a/static/images/integrations/pagerduty/001.png and b/static/images/integrations/pagerduty/001.png differdiff --git a/zerver/webhooks/pagerduty/tests.py b/zerver/webhooks/pagerduty/tests.pyindex 3ac28a9cdc0..70bbb871dc8 100644--- a/zerver/webhooks/pagerduty/tests.py+++ b/zerver/webhooks/pagerduty/tests.py@@ -2,25 +2,27 @@ from zerver.lib.test_classes import WebhookTestCaseclass PagerDutyHookTests(WebhookTestCase):+ V2_TOPIC = "Incident My new incident (#33)"+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)+ expected_message = "Incident [My new 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))."+ self.check_webhook("trigger_v2", self.V2_TOPIC, expected_message)def test_triggerer_v3(self) -> None:expected_message = "Incident [Test Incident 3 (#9)](https://pig208.pagerduty.com/incidents/PFQZPSY) triggered by [pig208](https://pig208.pagerduty.com/services/PA2P440) (assigned to [PIG 208](https://pig208.pagerduty.com/users/PJ0LVEB))."self.check_webhook("triggered_v3", "Incident Test Incident 3 (#9)", expected_message)def test_trigger_without_assignee_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 nobody).\n\n``` quote\nMy new incident\n```"- self.check_webhook("trigger_without_assignee_v2", "Incident 33", expected_message)+ expected_message = "Incident [My new incident (#33)](https://webdemo.pagerduty.com/incidents/PRORDTY) triggered by [Production XDB Cluster](https://webdemo.pagerduty.com/services/PN49J75) (assigned to nobody)."+ self.check_webhook("trigger_without_assignee_v2", self.V2_TOPIC, 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_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)+ expected_message = "Incident [My new incident (#33)](https://webdemo.pagerduty.com/incidents/PRORDTY) resolved by [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV)."+ self.check_webhook("resolve_v2", self.V2_TOPIC, expected_message)def test_resolved_v3(self) -> None:expected_message = "Incident [Test Incident (#6)](https://pig208.pagerduty.com/incidents/PCPZE64) resolved by [PIG 208](https://pig208.pagerduty.com/users/PJ0LVEB)."@@ -31,12 +33,12 @@ class PagerDutyHookTests(WebhookTestCase):self.check_webhook("acknowledged_v3", "Incident Test Incident (#10)", expected_message)def test_acknowledge_v2(self) -> None:- expected_message = "Incident [33](https://webdemo.pagerduty.com/incidents/PRORDTY) acknowledged by [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV).\n\n``` quote\nMy new incident\n```"- self.check_webhook("acknowledge_v2", "Incident 33", expected_message)+ expected_message = "Incident [My new incident (#33)](https://webdemo.pagerduty.com/incidents/PRORDTY) acknowledged by [Laura Haley](https://webdemo.pagerduty.com/users/P553OPV)."+ self.check_webhook("acknowledge_v2", self.V2_TOPIC, expected_message)def test_incident_assigned_v2(self) -> None:- expected_message = "Incident [33](https://webdemo.pagerduty.com/incidents/PRORDTY) assigned to [Wiley Jacobson](https://webdemo.pagerduty.com/users/PFBSJ2Z).\n\n``` quote\nMy new incident\n```"- self.check_webhook("assign_v2", "Incident 33", expected_message)+ expected_message = "Incident [My new incident (#33)](https://webdemo.pagerduty.com/incidents/PRORDTY) assigned to [Wiley Jacobson](https://webdemo.pagerduty.com/users/PFBSJ2Z)."+ self.check_webhook("assign_v2", self.V2_TOPIC, expected_message)def test_reassigned_v3(self) -> None:expected_message = "Incident [Test Incident (#3)](https://pig208.pagerduty.com/incidents/PIQUG8X) reassigned to [Test User](https://pig208.pagerduty.com/users/PI9DT01)."diff --git a/zerver/webhooks/pagerduty/view.py b/zerver/webhooks/pagerduty/view.pyindex ac36894367f..b43b2ef2ff4 100644--- a/zerver/webhooks/pagerduty/view.py+++ b/zerver/webhooks/pagerduty/view.py@@ -77,7 +77,10 @@ def build_pagerduty_formatdict_v2(message: WildValue) -> FormatDictType:format_dict["action"] = PAGER_DUTY_EVENT_NAMES_V2[message["event"].tame(check_string)]format_dict["incident_id"] = message["incident"]["id"].tame(check_string)- format_dict["incident_num_title"] = message["incident"]["incident_number"].tame(check_int)+ format_dict["incident_num_title"] = NUM_TITLE.format(+ incident_num=message["incident"]["incident_number"].tame(check_int),+ incident_title=message["incident"]["title"].tame(check_string),+ )format_dict["incident_url"] = message["incident"]["html_url"].tame(check_string)format_dict["service_name"] = message["incident"]["service"]["name"].tame(check_string)@@ -100,9 +103,9 @@ def build_pagerduty_formatdict_v2(message: WildValue) -> FormatDictType:url=last_status_change_by["html_url"].tame(check_string),)- trigger_description = message["incident"].get("description").tame(check_none_or(check_string))- if trigger_description is not None:- format_dict["trigger_message"] = TRIGGER_MESSAGE.format(message=trigger_description)+ # Pagerduty has deprecated incident.description for v2 events.+ # It will have the same value as incident.title.+ format_dict["trigger_message"] = ""return format_dict