Update __init__.py

This commit is contained in:
Den Delimarsky 🌺
2025-09-20 08:46:32 -07:00
parent 5659c869b5
commit db9d97bcbd

View File

@@ -53,17 +53,13 @@ ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
client = httpx.Client(verify=ssl_context) client = httpx.Client(verify=ssl_context)
def _github_token(cli_token: str | None = None) -> str | None: def _github_token(cli_token: str | None = None) -> str | None:
return cli_token or os.getenv("GH_TOKEN") or os.getenv("GITHUB_TOKEN") """Return sanitized GitHub token (cli arg takes precedence) or None."""
return ((cli_token or os.getenv("GH_TOKEN") or os.getenv("GITHUB_TOKEN") or "").strip()) or None
def _github_auth_headers(cli_token: str | None = None) -> dict: def _github_auth_headers(cli_token: str | None = None) -> dict:
"""Headers for GitHub REST API requests. """Return Authorization header dict only when a non-empty token exists."""
- Uses Bearer auth if token present
"""
headers = {}
token = _github_token(cli_token) token = _github_token(cli_token)
if token: return {"Authorization": f"Bearer {token}"} if token else {}
headers["Authorization"] = f"Bearer {token}"
return headers
# Constants # Constants
AI_CHOICES = { AI_CHOICES = {
@@ -447,7 +443,7 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri
api_url, api_url,
timeout=30, timeout=30,
follow_redirects=True, follow_redirects=True,
headers=_github_auth_headers(github_token) or None, headers=_github_auth_headers(github_token),
) )
status = response.status_code status = response.status_code
if status != 200: if status != 200:
@@ -500,7 +496,7 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri
download_url, download_url,
timeout=60, timeout=60,
follow_redirects=True, follow_redirects=True,
headers=_github_auth_headers(github_token) or None, headers=_github_auth_headers(github_token),
) as response: ) as response:
if response.status_code != 200: if response.status_code != 200:
body_sample = response.text[:400] body_sample = response.text[:400]