diff --git a/odoo_devkit/local_runtime.py b/odoo_devkit/local_runtime.py index bec2754..54ba01c 100644 --- a/odoo_devkit/local_runtime.py +++ b/odoo_devkit/local_runtime.py @@ -2088,7 +2088,7 @@ def resolve_artifact_runtime_source_repository_refs( runtime_values: dict[str, str], ) -> tuple[dict[str, str], tuple[dict[str, str], ...]]: resolved_values = dict(runtime_values) - github_token = resolve_source_github_token(runtime_values) + github_token, github_token_source = resolve_source_github_token(runtime_values) selector_metadata: list[dict[str, str]] = [] for env_key in ARTIFACT_SOURCE_ENV_KEYS: raw_value = runtime_values.get(env_key, "") @@ -2103,6 +2103,7 @@ def resolve_artifact_runtime_source_repository_refs( repository=repository, ref=ref, github_token=github_token, + github_token_source=github_token_source, ) selector_metadata.append( { @@ -2116,13 +2117,24 @@ def resolve_artifact_runtime_source_repository_refs( return resolved_values, tuple(selector_metadata) -def resolve_source_github_token(runtime_values: dict[str, str]) -> str | None: - return clean_optional_value(runtime_values.get("GITHUB_TOKEN")) or first_clean_optional_value( - os.environ.get(environment_key) for environment_key in (*SOURCE_GITHUB_TOKEN_ENV_KEYS, "GITHUB_TOKEN", "GH_TOKEN") - ) +def resolve_source_github_token(runtime_values: dict[str, str]) -> tuple[str | None, str]: + configured_token = clean_optional_value(runtime_values.get("GITHUB_TOKEN")) + if configured_token is not None: + return configured_token, "runtime:GITHUB_TOKEN" + for environment_key in (*SOURCE_GITHUB_TOKEN_ENV_KEYS, "GITHUB_TOKEN", "GH_TOKEN"): + environment_token = clean_optional_value(os.environ.get(environment_key)) + if environment_token is not None: + return environment_token, f"env:{environment_key}" + return None, "none" -def resolve_source_repository_ref_to_git_sha(*, repository: str, ref: str, github_token: str | None = None) -> str: +def resolve_source_repository_ref_to_git_sha( + *, + repository: str, + ref: str, + github_token: str | None = None, + github_token_source: str = "unknown", +) -> str: normalized_repository = repository.strip() normalized_ref = ref.strip() if GIT_SHA_PATTERN.fullmatch(normalized_ref): @@ -2139,6 +2151,7 @@ def resolve_source_repository_ref_to_git_sha(*, repository: str, ref: str, githu "GIT_CONFIG_VALUE_0": f"AUTHORIZATION: basic {encoded_auth}", } ) + print(f"artifact_source_token_source={github_token_source} auth_header_configured={str(normalized_token is not None).lower()}") ls_remote_result = subprocess.run( ["git", "ls-remote", "--refs", remote_url, normalized_ref], capture_output=True, diff --git a/tests/test_runtime.py b/tests/test_runtime.py index 372c3c4..5201602 100644 --- a/tests/test_runtime.py +++ b/tests/test_runtime.py @@ -1157,6 +1157,7 @@ def fake_run_command( repository="cbusillo/disable_odoo_online", ref="main", github_token="gh-token", + github_token_source="runtime:GITHUB_TOKEN", ) addon_build_arg = next(argument for argument in captured_build_args if argument.startswith("ODOO_ADDON_REPOSITORIES=")) self.assertEqual( @@ -1361,6 +1362,7 @@ def fake_run_command( repository="cbusillo/disable_odoo_online", ref="release-19", github_token="gh-token", + github_token_source="runtime:GITHUB_TOKEN", ) addon_build_arg = next(argument for argument in captured_build_args if argument.startswith("ODOO_ADDON_REPOSITORIES=")) self.assertEqual( @@ -1627,6 +1629,7 @@ def test_resolve_artifact_runtime_source_refs_uses_environment_token_fallback(se repository="cbusillo/disable_odoo_online", ref="main", github_token="env-token", + github_token_source="env:GITHUB_TOKEN", ) self.assertEqual( resolved_values["ODOO_ADDON_REPOSITORIES"], @@ -1664,6 +1667,7 @@ def test_resolve_artifact_runtime_source_refs_uses_dedicated_source_token_env(se repository="cbusillo/disable_odoo_online", ref="main", github_token="source-env-token", + github_token_source="env:ODOO_DEVKIT_SOURCE_GITHUB_TOKEN", ) def test_resolve_artifact_runtime_source_refs_supports_ci_source_token_env(self) -> None: @@ -1687,6 +1691,7 @@ def test_resolve_artifact_runtime_source_refs_supports_ci_source_token_env(self) repository="cbusillo/disable_odoo_online", ref="main", github_token="ci-source-token", + github_token_source="env:ODOO_SOURCE_GITHUB_TOKEN", ) def test_resolve_artifact_runtime_source_refs_prefers_runtime_github_token(self) -> None: @@ -1705,6 +1710,7 @@ def test_resolve_artifact_runtime_source_refs_prefers_runtime_github_token(self) repository="cbusillo/disable_odoo_online", ref="main", github_token="source-token", + github_token_source="runtime:GITHUB_TOKEN", ) def test_resolve_source_repository_ref_to_git_sha_rejects_ambiguous_matches(self) -> None: