mirror of
https://github.com/github/spec-kit.git
synced 2026-02-04 23:13:08 +00:00
expose token as an argument through cli --github-token
This commit is contained in:
@@ -52,15 +52,15 @@ import truststore
|
|||||||
ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
ssl_context = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
||||||
client = httpx.Client(verify=ssl_context)
|
client = httpx.Client(verify=ssl_context)
|
||||||
|
|
||||||
def _github_token() -> str | None:
|
def _github_token(cli_token: str | None = None) -> str | None:
|
||||||
return os.getenv("GH_TOKEN") or os.getenv("GITHUB_TOKEN")
|
return cli_token or os.getenv("GH_TOKEN") or os.getenv("GITHUB_TOKEN")
|
||||||
|
|
||||||
def _github_auth_headers() -> dict:
|
def _github_auth_headers(cli_token: str | None = None) -> dict:
|
||||||
"""Headers for GitHub REST API requests.
|
"""Headers for GitHub REST API requests.
|
||||||
- Uses Bearer auth if token present
|
- Uses Bearer auth if token present
|
||||||
"""
|
"""
|
||||||
headers = {}
|
headers = {}
|
||||||
token = _github_token()
|
token = _github_token(cli_token)
|
||||||
if token:
|
if token:
|
||||||
headers["Authorization"] = f"Bearer {token}"
|
headers["Authorization"] = f"Bearer {token}"
|
||||||
return headers
|
return headers
|
||||||
@@ -429,7 +429,7 @@ def init_git_repo(project_path: Path, quiet: bool = False) -> bool:
|
|||||||
os.chdir(original_cwd)
|
os.chdir(original_cwd)
|
||||||
|
|
||||||
|
|
||||||
def download_template_from_github(ai_assistant: str, download_dir: Path, *, script_type: str = "sh", verbose: bool = True, show_progress: bool = True, client: httpx.Client = None, debug: bool = False) -> Tuple[Path, dict]:
|
def download_template_from_github(ai_assistant: str, download_dir: Path, *, script_type: str = "sh", verbose: bool = True, show_progress: bool = True, client: httpx.Client = None, debug: bool = False, github_token: str = None) -> Tuple[Path, dict]:
|
||||||
repo_owner = "github"
|
repo_owner = "github"
|
||||||
repo_name = "spec-kit"
|
repo_name = "spec-kit"
|
||||||
if client is None:
|
if client is None:
|
||||||
@@ -444,7 +444,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() or None,
|
headers=_github_auth_headers(github_token) or None,
|
||||||
)
|
)
|
||||||
status = response.status_code
|
status = response.status_code
|
||||||
if status != 200:
|
if status != 200:
|
||||||
@@ -497,7 +497,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() or None,
|
headers=_github_auth_headers(github_token) or None,
|
||||||
) as response:
|
) as response:
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
body_sample = response.text[:400]
|
body_sample = response.text[:400]
|
||||||
@@ -542,7 +542,7 @@ def download_template_from_github(ai_assistant: str, download_dir: Path, *, scri
|
|||||||
return zip_path, metadata
|
return zip_path, metadata
|
||||||
|
|
||||||
|
|
||||||
def download_and_extract_template(project_path: Path, ai_assistant: str, script_type: str, is_current_dir: bool = False, *, verbose: bool = True, tracker: StepTracker | None = None, client: httpx.Client = None, debug: bool = False) -> Path:
|
def download_and_extract_template(project_path: Path, ai_assistant: str, script_type: str, is_current_dir: bool = False, *, verbose: bool = True, tracker: StepTracker | None = None, client: httpx.Client = None, debug: bool = False, github_token: str = None) -> Path:
|
||||||
"""Download the latest release and extract it to create a new project.
|
"""Download the latest release and extract it to create a new project.
|
||||||
Returns project_path. Uses tracker if provided (with keys: fetch, download, extract, cleanup)
|
Returns project_path. Uses tracker if provided (with keys: fetch, download, extract, cleanup)
|
||||||
"""
|
"""
|
||||||
@@ -559,7 +559,8 @@ def download_and_extract_template(project_path: Path, ai_assistant: str, script_
|
|||||||
verbose=verbose and tracker is None,
|
verbose=verbose and tracker is None,
|
||||||
show_progress=(tracker is None),
|
show_progress=(tracker is None),
|
||||||
client=client,
|
client=client,
|
||||||
debug=debug
|
debug=debug,
|
||||||
|
github_token=github_token
|
||||||
)
|
)
|
||||||
if tracker:
|
if tracker:
|
||||||
tracker.complete("fetch", f"release {meta['release']} ({meta['size']:,} bytes)")
|
tracker.complete("fetch", f"release {meta['release']} ({meta['size']:,} bytes)")
|
||||||
@@ -754,6 +755,7 @@ def init(
|
|||||||
here: bool = typer.Option(False, "--here", help="Initialize project in the current directory instead of creating a new one"),
|
here: bool = typer.Option(False, "--here", help="Initialize project in the current directory instead of creating a new one"),
|
||||||
skip_tls: bool = typer.Option(False, "--skip-tls", help="Skip SSL/TLS verification (not recommended)"),
|
skip_tls: bool = typer.Option(False, "--skip-tls", help="Skip SSL/TLS verification (not recommended)"),
|
||||||
debug: bool = typer.Option(False, "--debug", help="Show verbose diagnostic output for network and extraction failures"),
|
debug: bool = typer.Option(False, "--debug", help="Show verbose diagnostic output for network and extraction failures"),
|
||||||
|
github_token: str = typer.Option(None, "--github-token", help="GitHub token to use for API requests (or set GH_TOKEN or GITHUB_TOKEN environment variable)"),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Initialize a new Specify project from the latest template.
|
Initialize a new Specify project from the latest template.
|
||||||
@@ -908,7 +910,7 @@ def init(
|
|||||||
local_ssl_context = ssl_context if verify else False
|
local_ssl_context = ssl_context if verify else False
|
||||||
local_client = httpx.Client(verify=local_ssl_context)
|
local_client = httpx.Client(verify=local_ssl_context)
|
||||||
|
|
||||||
download_and_extract_template(project_path, selected_ai, selected_script, here, verbose=False, tracker=tracker, client=local_client, debug=debug)
|
download_and_extract_template(project_path, selected_ai, selected_script, here, verbose=False, tracker=tracker, client=local_client, debug=debug, github_token=github_token)
|
||||||
|
|
||||||
# Ensure scripts are executable (POSIX)
|
# Ensure scripts are executable (POSIX)
|
||||||
ensure_executable_scripts(project_path, tracker=tracker)
|
ensure_executable_scripts(project_path, tracker=tracker)
|
||||||
|
|||||||
Reference in New Issue
Block a user