From 2131749d31bf255f6383c767d7927a85a62a3aab Mon Sep 17 00:00:00 2001 From: codejedi365 Date: Thu, 6 Feb 2025 22:18:51 -0500 Subject: [PATCH] fix(config): refactors default token resolution to prevent pre-mature insecure URL error Due to the previous default token loading, PSR configuration load would initate the default RemoteConfig. During validation of the remote config, the HVCS object was initialized and upon initialization the URL is evaluated for insecure protocol causing errors when the URL was pulled from the env. This change removes the need for initialization which means the URL validation will not occur pre-maturely Resolves: #1169, #1074 --- src/semantic_release/cli/config.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/semantic_release/cli/config.py b/src/semantic_release/cli/config.py index 7e5c31131..cd2d1bf13 100644 --- a/src/semantic_release/cli/config.py +++ b/src/semantic_release/cli/config.py @@ -54,7 +54,6 @@ ParserLoadError, ) from semantic_release.helpers import dynamic_import -from semantic_release.hvcs.remote_hvcs_base import RemoteHvcsBase from semantic_release.version.declaration import ( PatternVersionDeclaration, TomlVersionDeclaration, @@ -287,15 +286,18 @@ def set_default_token(self) -> Self: def _get_default_token(self) -> str | None: hvcs_client_class = _known_hvcs[self.type] - default_hvcs_instance = hvcs_client_class("git@example.com:owner/project.git") - if not isinstance(default_hvcs_instance, RemoteHvcsBase): - return None - default_token_name = default_hvcs_instance.DEFAULT_ENV_TOKEN_NAME - if not default_token_name: - return None + default_token_name = ( + getattr(hvcs_client_class, "DEFAULT_ENV_TOKEN_NAME") # noqa: B009 + if hasattr(hvcs_client_class, "DEFAULT_ENV_TOKEN_NAME") + else "" + ) - return EnvConfigVar(env=default_token_name).getvalue() + return ( + EnvConfigVar(env=default_token_name).getvalue() + if default_token_name + else None + ) @model_validator(mode="after") def check_url_scheme(self) -> Self: