Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/appveyor: Use datetime_to_global_time and ISO 8601 syntax.
Niloth P4f8d07e744d3
diff --git a/zerver/webhooks/appveyor/tests.py b/zerver/webhooks/appveyor/tests.pyindex d37c150ac6f..12bf2a0449a 100644--- a/zerver/webhooks/appveyor/tests.py+++ b/zerver/webhooks/appveyor/tests.py@@ -14,8 +14,8 @@ class AppveyorHookTests(WebhookTestCase):expected_message = """[Build Hubot-DSC-Resource 2.0.59 completed](https://ci.appveyor.com/project/joebloggs/hubot-dsc-resource/build/2.0.59):* **Commit**: [c06e208b47: Increment version number.](https://github.com/joebloggs/Hubot-DSC-Resource/commit/c06e208b47) by Joe Bloggs-* **Started**: <time:9/9/2018 7:04 PM>-* **Finished**: <time:9/9/2018 7:06 PM>+* **Started**: <time:2018-09-09T19:04:00+00:00>+* **Finished**: <time:2018-09-09T19:06:00+00:00>""".strip()self.check_webhook("appveyor_build_success", expected_topic_name, expected_message)@@ -28,8 +28,8 @@ class AppveyorHookTests(WebhookTestCase):expected_message = """[Build Hubot-DSC-Resource 2.0.59 failed](https://ci.appveyor.com/project/joebloggs/hubot-dsc-resource/build/2.0.59):* **Commit**: [c06e208b47: Increment version number.](https://github.com/joebloggs/Hubot-DSC-Resource/commit/c06e208b47) by Joe Bloggs-* **Started**: <time:9/9/2018 7:04 PM>-* **Finished**: <time:9/9/2018 7:06 PM>+* **Started**: <time:2018-09-09T19:04:00+00:00>+* **Finished**: <time:2018-09-09T19:06:00+00:00>""".strip()self.check_webhook("appveyor_build_failure", expected_topic_name, expected_message)diff --git a/zerver/webhooks/appveyor/view.py b/zerver/webhooks/appveyor/view.pyindex 7188b48604e..8050bed9cdc 100644--- a/zerver/webhooks/appveyor/view.py+++ b/zerver/webhooks/appveyor/view.py@@ -1,8 +1,11 @@+from datetime import datetime, timezone+from django.http import HttpRequest, HttpResponsefrom pydantic.alias_generators import to_snakefrom zerver.decorator import webhook_viewfrom zerver.lib.response import json_success+from zerver.lib.timestamp import datetime_to_global_timefrom zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpointfrom zerver.lib.validator import WildValue, check_stringfrom zerver.lib.webhooks.common import check_send_webhook_message@@ -12,11 +15,17 @@ APPVEYOR_TOPIC_TEMPLATE = "{project_name}"APPVEYOR_MESSAGE_TEMPLATE = """[Build {project_name} {build_version} {status}]({build_url}):* **Commit**: [{commit_id}: {commit_message}]({commit_url}) by {committer_name}-* **Started**: <time:{started}>-* **Finished**: <time:{finished}>+* **Started**: {started}+* **Finished**: {finished}""".strip()+def get_global_time(dt_str: str) -> str:+ return datetime_to_global_time(+ datetime.strptime(dt_str, "%m/%d/%Y %I:%M %p").replace(tzinfo=timezone.utc)+ )++@webhook_view("Appveyor")@typed_endpointdef api_appveyor_webhook(@@ -52,6 +61,9 @@ def get_body(payload: WildValue) -> str:"started","finished",]- data = {to_snake(field): event_data[field].tame(check_string) for field in fields}+ data = {+ to_snake(field): get_global_time(value) if field in ["started", "finished"] else value+ for field, value in ((field, event_data[field].tame(check_string)) for field in fields)+ }return APPVEYOR_MESSAGE_TEMPLATE.format(**data)