|
53 | 53 | client = httpx.Client(verify=ssl_context) |
54 | 54 |
|
55 | 55 | def _github_token(cli_token: str | None = None) -> str | None: |
56 | | - return cli_token or os.getenv("GH_TOKEN") or os.getenv("GITHUB_TOKEN") |
| 56 | + """Return sanitized GitHub token (cli arg takes precedence) or None.""" |
| 57 | + return ((cli_token or os.getenv("GH_TOKEN") or os.getenv("GITHUB_TOKEN") or "").strip()) or None |
57 | 58 |
|
58 | 59 | def _github_auth_headers(cli_token: str | None = None) -> dict: |
59 | | - """Headers for GitHub REST API requests. |
60 | | - - Uses Bearer auth if token present |
61 | | - """ |
62 | | - headers = {} |
| 60 | + """Return Authorization header dict only when a non-empty token exists.""" |
63 | 61 | token = _github_token(cli_token) |
64 | | - if token: |
65 | | - headers["Authorization"] = f"Bearer {token}" |
66 | | - return headers |
| 62 | + return {"Authorization": f"Bearer {token}"} if token else {} |
67 | 63 |
|
68 | 64 | # Constants |
69 | 65 | AI_CHOICES = { |
@@ -447,7 +443,7 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri |
447 | 443 | api_url, |
448 | 444 | timeout=30, |
449 | 445 | follow_redirects=True, |
450 | | - headers=_github_auth_headers(github_token) or None, |
| 446 | + headers=_github_auth_headers(github_token), |
451 | 447 | ) |
452 | 448 | status = response.status_code |
453 | 449 | if status != 200: |
@@ -500,7 +496,7 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri |
500 | 496 | download_url, |
501 | 497 | timeout=60, |
502 | 498 | follow_redirects=True, |
503 | | - headers=_github_auth_headers(github_token) or None, |
| 499 | + headers=_github_auth_headers(github_token), |
504 | 500 | ) as response: |
505 | 501 | if response.status_code != 200: |
506 | 502 | body_sample = response.text[:400] |
|
0 commit comments