Skip to content

Commit db9d97b

Browse files
committed
Update __init__.py
1 parent 5659c86 commit db9d97b

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

src/specify_cli/__init__.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,13 @@
5353
client = httpx.Client(verify=ssl_context)
5454

5555
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
5758

5859
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."""
6361
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 {}
6763

6864
# Constants
6965
AI_CHOICES = {
@@ -447,7 +443,7 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri
447443
api_url,
448444
timeout=30,
449445
follow_redirects=True,
450-
headers=_github_auth_headers(github_token) or None,
446+
headers=_github_auth_headers(github_token),
451447
)
452448
status = response.status_code
453449
if status != 200:
@@ -500,7 +496,7 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri
500496
download_url,
501497
timeout=60,
502498
follow_redirects=True,
503-
headers=_github_auth_headers(github_token) or None,
499+
headers=_github_auth_headers(github_token),
504500
) as response:
505501
if response.status_code != 200:
506502
body_sample = response.text[:400]

0 commit comments

Comments
 (0)