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.

webhooks/raygun: Use datetime_to_global_time and ISO 8601 syntax.

Niloth P47f841184048
diff --git a/zerver/webhooks/raygun/tests.py b/zerver/webhooks/raygun/tests.py
index a74ea700db2..ee9e752f0a0 100644
--- a/zerver/webhooks/raygun/tests.py
+++ b/zerver/webhooks/raygun/tests.py
@@ -10,7 +10,7 @@ class RaygunHookTests(WebhookTestCase):
expected_topic_name = "test"
expected_message = """
[Error](https://app.raygun.com/error-url) status changed to **Ignored** by Emma Cat:
-* **Timestamp**: <time:Wed Jan 28 01:49:36 1970>
+* **Timestamp**: <time:1970-01-28T01:49:36+00:00>
* **Application details**: [Best App](http://app.raygun.io/application-url)
""".strip()
@@ -29,7 +29,7 @@ Anita Peacock commented on [Error](https://app.raygun.com/error-url):
``` quote
Ignoring these errors
```
-* **Timestamp**: <time:Wed Jan 28 01:49:36 1970>
+* **Timestamp**: <time:1970-01-28T01:49:36+00:00>
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
@@ -44,7 +44,7 @@ Ignoring these errors
expected_topic_name = "test"
expected_message = """
Amy Loondon assigned [Error](https://app.raygun.com/error-url) to Kyle Kenny:
-* **Timestamp**: <time:Wed Jan 28 01:49:36 1970>
+* **Timestamp**: <time:1970-01-28T01:49:36+00:00>
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
@@ -59,8 +59,8 @@ Amy Loondon assigned [Error](https://app.raygun.com/error-url) to Kyle Kenny:
expected_topic_name = "test"
expected_message = """
One minute [follow-up error](http://app.raygun.io/error-url):
-* **First occurred**: <time:Wed Jan 28 01:49:36 1970>
-* **Last occurred**: <time:Wed Jan 28 01:49:36 1970>
+* **First occurred**: <time:1970-01-28T01:49:36+00:00>
+* **Last occurred**: <time:1970-01-28T01:49:36+00:00>
* 1 users affected with 1 total occurrences
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
@@ -76,8 +76,8 @@ One minute [follow-up error](http://app.raygun.io/error-url):
expected_topic_name = "test"
expected_message = """
Hourly [follow-up error](http://app.raygun.io/error-url):
-* **First occurred**: <time:Wed Jan 28 01:49:36 1970>
-* **Last occurred**: <time:Wed Jan 28 01:49:36 1970>
+* **First occurred**: <time:1970-01-28T01:49:36+00:00>
+* **Last occurred**: <time:1970-01-28T01:49:36+00:00>
* 1 users affected with 1 total occurrences
* **Application details**: [application name](http://app.raygun.io/application-url)
""".strip()
@@ -93,8 +93,8 @@ Hourly [follow-up error](http://app.raygun.io/error-url):
expected_topic_name = "test"
expected_message = """
New [Error](http://app.raygun.io/error-url) occurred:
-* **First occurred**: <time:Wed Jan 28 01:49:36 1970>
-* **Last occurred**: <time:Wed Jan 28 01:49:36 1970>
+* **First occurred**: <time:1970-01-28T01:49:36+00:00>
+* **Last occurred**: <time:1970-01-28T01:49:36+00:00>
* 1 users affected with 1 total occurrences
* **Tags**: test, error-page, v1.0.1, env:staging
* **Affected user**: a9b7d8...33846
@@ -114,8 +114,8 @@ New [Error](http://app.raygun.io/error-url) occurred:
expected_topic_name = "test"
expected_message = """
[Error](http://app.raygun.io/error-url) reoccurred:
-* **First occurred**: <time:Wed Jan 28 01:49:36 1970>
-* **Last occurred**: <time:Wed Jan 28 01:49:36 1970>
+* **First occurred**: <time:1970-01-28T01:49:36+00:00>
+* **Last occurred**: <time:1970-01-28T01:49:36+00:00>
* 1 users affected with 1 total occurrences
* **Tags**: test, error-page, v1.0.1, env:staging
* **Affected user**: a9b7d8...33846
diff --git a/zerver/webhooks/raygun/view.py b/zerver/webhooks/raygun/view.py
index 2426e81af1a..17b8d2b5f21 100644
--- a/zerver/webhooks/raygun/view.py
+++ b/zerver/webhooks/raygun/view.py
@@ -1,10 +1,12 @@
-import time
+from datetime import timezone
+import dateutil.parser
from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
from zerver.lib.response import json_success
+from zerver.lib.timestamp import datetime_to_global_time
from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint
from zerver.lib.validator import WildValue, check_anything, check_int, check_list, check_string
from zerver.lib.webhooks.common import check_send_webhook_message
@@ -81,7 +83,7 @@ def make_time_chunk(error_dict: WildValue) -> str:
time_last = parse_time(error_dict["lastOccurredOn"].tame(check_string))
# Provide time information about this error,
- return f"* **First occurred**: <time:{time_first}>\n* **Last occurred**: <time:{time_last}>\n"
+ return f"* **First occurred**: {time_first}\n* **Last occurred**: {time_last}\n"
def make_message_chunk(message: str) -> str:
@@ -252,7 +254,7 @@ def activity_message(payload: WildValue) -> str:
assigned_to = payload["error"]["assignedTo"].tame(check_string)
message += f"{user} assigned {error_link_md} to {assigned_to}:\n"
- message += "* **Timestamp**: <time:{}>\n".format(
+ message += "* **Timestamp**: {}\n".format(
parse_time(payload["error"]["activityDate"].tame(check_string))
)
@@ -285,7 +287,7 @@ def compose_activity_message(payload: WildValue) -> str:
raise UnsupportedWebhookEventTypeError(event_type)
-def parse_time(timestamp: str) -> str:
+def parse_time(dt_str: str) -> str:
"""Parses and returns the timestamp provided
:param timestamp: The timestamp provided by the payload
@@ -294,8 +296,5 @@ def parse_time(timestamp: str) -> str:
# Raygun provides two timestamp format, one with the Z at the end,
# and one without the Z.
-
- format = "%Y-%m-%dT%H:%M:%S"
- format += "Z" if timestamp[-1:] == "Z" else ""
- parsed_time = time.strftime("%c", time.strptime(timestamp, format))
- return parsed_time
+ dt = dateutil.parser.parse(dt_str).replace(tzinfo=timezone.utc)
+ return datetime_to_global_time(dt)