From 261fc933348a2d3e9b6e82e299150503609ec705 Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Sun, 30 Nov 2025 19:56:27 +0530 Subject: [PATCH 1/4] openshift: Allow using the deployment ID and time in the message. While the message template customization function had `dep_time` and `dep_id` parameters, the `deployment` dict was not populated with those fields previously. --- zulip/integrations/openshift/post_deploy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zulip/integrations/openshift/post_deploy b/zulip/integrations/openshift/post_deploy index da2bdb912..4384f98c1 100755 --- a/zulip/integrations/openshift/post_deploy +++ b/zulip/integrations/openshift/post_deploy @@ -37,6 +37,8 @@ def get_deployment_details() -> Dict[str, str]: url=os.environ["OPENSHIFT_APP_DNS"], branch=splits[2], commit_id=splits[3], + dep_id=splits[1], + dep_time=splits[0], ) From 8a165f17f570921f044eeeba1f6e09c4269edec4 Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Fri, 5 Dec 2025 01:12:08 +0530 Subject: [PATCH 2/4] Add a datetime_to_global_time helper function. --- zulip/zulip/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index c8d6955de..540c347cb 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -11,6 +11,7 @@ import types import urllib.parse from configparser import ConfigParser +from datetime import datetime from typing import ( IO, Any, @@ -351,6 +352,12 @@ def validate_boolean_field(field: Optional[str]) -> Union[bool, None]: return None +def datetime_to_global_time(dt: datetime) -> str: + if dt.tzinfo is None: + raise TimeZoneMissingError(f"Datetime {dt} does not have a time zone.") + return f"" + + class ZulipError(Exception): pass @@ -367,6 +374,10 @@ class UnrecoverableNetworkError(ZulipError): pass +class TimeZoneMissingError(ZulipError): + pass + + class Client: def __init__( self, From ac760301de664ae7e66cbb52d0bca9e49e239ccf Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Fri, 5 Dec 2025 06:08:08 +0530 Subject: [PATCH 3/4] requirements: Add backports.datetime_fromisoformat for Py<3.11. Co-authored-by: Anders Kaseorg --- pyproject.toml | 1 + zulip/setup.py | 1 + zulip/zulip/__init__.py | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index aad2b4dbc..28633465b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -60,6 +60,7 @@ warn_unreachable = true [[tool.mypy.overrides]] module = [ "apiai.*", + "backports.datetime_fromisoformat.*", "feedparser.*", "gitlint.*", "google.auth.*", diff --git a/zulip/setup.py b/zulip/setup.py index 137fc29ee..097bc684b 100755 --- a/zulip/setup.py +++ b/zulip/setup.py @@ -64,6 +64,7 @@ def recur_expand(target_root: Any, dir: Any) -> Generator[Tuple[str, List[str]], ], }, install_requires=[ + "backports-datetime-fromisoformat; python_version < '3.11'", "requests[security]>=0.12.1", "distro", "click", diff --git a/zulip/zulip/__init__.py b/zulip/zulip/__init__.py index 540c347cb..93fbc896f 100644 --- a/zulip/zulip/__init__.py +++ b/zulip/zulip/__init__.py @@ -35,6 +35,13 @@ # Ensure the Python version is supported assert sys.version_info >= (3, 6) +if sys.version_info < (3, 11): + from backports.datetime_fromisoformat import ( + datetime_fromisoformat as datetime_fromisoformat, # noqa: PLC0414 + ) +else: + datetime_fromisoformat = datetime.fromisoformat + logger = logging.getLogger(__name__) API_VERSTRING = "v1/" From 59fa607acc22d751bf15f6d9e7ad761d696d08cb Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Fri, 5 Dec 2025 00:18:00 +0530 Subject: [PATCH 4/4] openshift: Add a helper function to parse the datetime for the template. --- .../openshift/zulip_openshift_config.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/zulip/integrations/openshift/zulip_openshift_config.py b/zulip/integrations/openshift/zulip_openshift_config.py index ef71bfc57..98e5b1de0 100644 --- a/zulip/integrations/openshift/zulip_openshift_config.py +++ b/zulip/integrations/openshift/zulip_openshift_config.py @@ -1,6 +1,8 @@ # https://github.com/python/mypy/issues/1141 from typing import Dict, Optional +import zulip + # Change these values to configure authentication for the plugin ZULIP_USER = "openshift-bot@example.com" ZULIP_API_KEY = "0123456789abcdef0123456789abcdef" @@ -28,6 +30,14 @@ def deployment_notice_destination(branch: str) -> Optional[Dict[str, str]]: return None +# To utilize Zulip's global times (https://zulip.com/help/global-times) +# call this function from format_deployment_message, and use the +# returned string in your message template. +def get_global_time(dt_str: str) -> str: + dt = zulip.datetime_fromisoformat(dt_str) + return zulip.datetime_to_global_time(dt) + + # Modify this function to change how deployments are displayed # # It takes the following arguments: @@ -39,9 +49,6 @@ def deployment_notice_destination(branch: str) -> Optional[Dict[str, str]]: # * commit_id = hash of the commit that triggered the deployment # * dep_id = deployment id # * dep_time = deployment timestamp -# -# To utilize Zulip's global times (https://zulip.com/help/global-times), -# use the syntax ``. def format_deployment_message( app_name: str = "", url: str = "",