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/trello: Use datetime_to_global_time and ISO 8601 syntax.

Niloth Pc04718375a59
diff --git a/zerver/webhooks/trello/tests.py b/zerver/webhooks/trello/tests.py
index 8989b061b21..f5952655ec3 100644
--- a/zerver/webhooks/trello/tests.py
+++ b/zerver/webhooks/trello/tests.py
@@ -43,11 +43,11 @@ class TrelloHookTests(WebhookTestCase):
self.check_webhook("removing_member_from_card", "Welcome Board", expected_message)
def test_trello_webhook_when_due_date_was_set(self) -> None:
- expected_message = "TomaszKolek set due date for [Card name](https://trello.com/c/9BduUcVQ) to <time:2016-05-11 10:00:00 UTC>."
+ expected_message = "TomaszKolek set due date for [Card name](https://trello.com/c/9BduUcVQ) to <time:2016-05-11T10:00:00+00:00>."
self.check_webhook("setting_due_date_to_card", "Welcome Board", expected_message)
def test_trello_webhook_when_due_date_was_changed(self) -> None:
- expected_message = "TomaszKolek changed due date for [Card name](https://trello.com/c/9BduUcVQ) from <time:2016-05-11 10:00:00 UTC> to <time:2016-05-24 10:00:00 UTC>."
+ expected_message = "TomaszKolek changed due date for [Card name](https://trello.com/c/9BduUcVQ) from <time:2016-05-11T10:00:00+00:00> to <time:2016-05-24T10:00:00+00:00>."
self.check_webhook("changing_due_date_on_card", "Welcome Board", expected_message)
def test_trello_webhook_when_due_date_was_removed(self) -> None:
diff --git a/zerver/webhooks/trello/view/card_actions.py b/zerver/webhooks/trello/view/card_actions.py
index 82a7f1d7519..7cc7dfb9543 100644
--- a/zerver/webhooks/trello/view/card_actions.py
+++ b/zerver/webhooks/trello/view/card_actions.py
@@ -1,6 +1,8 @@
from collections.abc import Mapping
+from datetime import datetime, timezone
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
+from zerver.lib.timestamp import datetime_to_global_time
from zerver.lib.validator import WildValue, check_bool, check_none_or, check_string
SUPPORTED_CARD_ACTIONS = [
@@ -57,8 +59,8 @@ ACTIONS_TO_MESSAGE_MAPPER = {
REMOVE_DESC: "removed description from {card_url_template}.",
ARCHIVE: "archived {card_url_template}.",
REOPEN: "reopened {card_url_template}.",
- SET_DUE_DATE: "set due date for {card_url_template} to <time:{due_date}>.",
- CHANGE_DUE_DATE: "changed due date for {card_url_template} from <time:{old_due_date}> to <time:{due_date}>.",
+ SET_DUE_DATE: "set due date for {card_url_template} to {due_date}.",
+ CHANGE_DUE_DATE: "changed due date for {card_url_template} from {old_due_date} to {due_date}.",
REMOVE_DUE_DATE: "removed the due date from {card_url_template}.",
ADD_LABEL: 'added a {color} label with "{text}" to {card_url_template}.',
REMOVE_LABEL: 'removed a {color} label with "{text}" from {card_url_template}.',
@@ -72,7 +74,8 @@ ACTIONS_TO_MESSAGE_MAPPER = {
def prettify_date(date_string: str) -> str:
- return date_string.replace("T", " ").replace(".000", "").replace("Z", " UTC")
+ dt = datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)
+ return datetime_to_global_time(dt)
def process_card_action(payload: WildValue, action_type: str) -> tuple[str, str] | None: