[loop-cycle-5] fix: get_token() priority order — config before repo-root fallback (#899)
Some checks failed
Tests / lint (push) Has been cancelled
Tests / test (push) Has been cancelled

This commit was merged in pull request #899.
This commit is contained in:
2026-03-22 01:52:40 +00:00
parent a3009fa32b
commit 77a8fc8b96
2 changed files with 24 additions and 10 deletions

View File

@@ -53,21 +53,26 @@ def load_config() -> dict:
def get_token(config: dict) -> str | None:
"""Get Gitea token from environment or file."""
"""Get Gitea token from environment or file.
Priority: config["token"] > config["token_file"] > .timmy_gitea_token
"""
if "token" in config:
return config["token"]
# Try timmy's token file
# Explicit token_file from config takes priority
token_file_str = config.get("token_file", "")
if token_file_str:
token_file = Path(token_file_str)
if token_file.exists():
return token_file.read_text().strip()
# Fallback: repo-root .timmy_gitea_token
repo_root = Path(__file__).resolve().parent.parent.parent
timmy_token_path = repo_root / ".timmy_gitea_token"
if timmy_token_path.exists():
return timmy_token_path.read_text().strip()
# Fallback to legacy token file
token_file = Path(config["token_file"]).expanduser()
if token_file.exists():
return token_file.read_text().strip()
return None