Update bot.py

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
Wiktor
2025-11-01 22:51:58 +01:00
committed by GitHub
parent 63dc74e8a2
commit 3d81b8d6b8

19
bot.py
View File

@@ -123,14 +123,11 @@ def _normalize_database_url(url: str) -> str:
if parsed.hostname not in {"localhost", "127.0.0.1", "::1"}: if parsed.hostname not in {"localhost", "127.0.0.1", "::1"}:
return url return url
username = parsed.username or "" if "@" in parsed.netloc:
password = parsed.password auth_prefix, _, _ = parsed.netloc.rpartition("@")
auth = "" auth_segment = f"{auth_prefix}@"
if username: else:
auth = username auth_segment = ""
if password is not None:
auth += f":{password}"
auth += "@"
if parsed.port is not None: if parsed.port is not None:
port_fragment = f":{parsed.port}" port_fragment = f":{parsed.port}"
@@ -138,7 +135,11 @@ def _normalize_database_url(url: str) -> str:
port_env = os.environ.get("POSTGRES_PORT") port_env = os.environ.get("POSTGRES_PORT")
port_fragment = f":{port_env}" if port_env else "" port_fragment = f":{port_env}" if port_env else ""
new_netloc = f"{auth}{host_override}{port_fragment}" target_host = host_override
if ":" in target_host and not target_host.startswith("["):
target_host = f"[{target_host}]"
new_netloc = f"{auth_segment}{target_host}{port_fragment}"
rebuilt = parsed._replace(netloc=new_netloc) rebuilt = parsed._replace(netloc=new_netloc)
return urlunparse(rebuilt) return urlunparse(rebuilt)