Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ warn_unreachable = true
[[tool.mypy.overrides]]
module = [
"apiai.*",
"backports.datetime_fromisoformat.*",
"feedparser.*",
"gitlint.*",
"google.auth.*",
Expand Down
2 changes: 2 additions & 0 deletions zulip/integrations/openshift/post_deploy
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)


Expand Down
13 changes: 10 additions & 3 deletions zulip/integrations/openshift/zulip_openshift_config.py
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
ZULIP_API_KEY = "0123456789abcdef0123456789abcdef"
Expand Down Expand Up @@ -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:
Expand All @@ -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 `<time:dep_time>`.
def format_deployment_message(
app_name: str = "",
url: str = "",
Expand Down
1 change: 1 addition & 0 deletions zulip/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 18 additions & 0 deletions zulip/zulip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import types
import urllib.parse
from configparser import ConfigParser
from datetime import datetime
from typing import (
IO,
Any,
Expand All @@ -34,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/"
Expand Down Expand Up @@ -351,6 +359,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"<time:{dt.isoformat(timespec='seconds')}>"


class ZulipError(Exception):
pass

Expand All @@ -367,6 +381,10 @@ class UnrecoverableNetworkError(ZulipError):
pass


class TimeZoneMissingError(ZulipError):
pass


class Client:
def __init__(
self,
Expand Down