@@ -596,6 +596,9 @@ def batch_analyze(
596596 overwrite : bool = typer .Option (
597597 False , "--overwrite" , "--full-sync" , help = "Ignore existing CSV; fetch full date range (default: incremental fetch from latest CSV data)"
598598 ),
599+ fetch_only : bool = typer .Option (
600+ False , "--fetch-only" , help = "Only fetch PR URLs to cache; skip analysis and labeling"
601+ ),
599602):
600603 """
601604 Batch analyze multiple PRs from a file or date range.
@@ -647,26 +650,26 @@ def batch_analyze(
647650 )
648651 raise typer .Exit (1 )
649652
650- # Require output_file unless --label is used
651- if not label and not output_file :
652- typer .echo ("Error: --output is required unless --label is used" , err = True )
653+ # Require output_file unless --label or --fetch-only is used
654+ if not label and not output_file and not fetch_only :
655+ typer .echo ("Error: --output is required unless --label or --fetch-only is used" , err = True )
653656 raise typer .Exit (1 )
654657
655658 # When labeling, default to writing CSV as well (override with --output)
656659 if label and not output_file :
657660 output_file = Path ("complexity-report.csv" )
658661
659- # Get credentials
660- openai_key = get_openai_api_key ()
662+ # Get credentials (skip LLM keys when fetch-only)
663+ openai_key = get_openai_api_key () if not fetch_only else None
661664
662- if provider == "openai" and not openai_key :
665+ if not fetch_only and provider == "openai" and not openai_key :
663666 typer .echo ("Error: OPENAI_API_KEY environment variable is required for openai provider" , err = True )
664667 typer .echo ("Set it with: export OPENAI_API_KEY='your-key'" , err = True )
665668 raise typer .Exit (1 )
666- if provider == "anthropic" and not get_anthropic_api_key ():
669+ if not fetch_only and provider == "anthropic" and not get_anthropic_api_key ():
667670 typer .echo ("Error: ANTHROPIC_API_KEY is required for anthropic provider" , err = True )
668671 raise typer .Exit (1 )
669- if provider == "bedrock" :
672+ if not fetch_only and provider == "bedrock" :
670673 typer .echo ("Using Bedrock provider. Ensure AWS_PROFILE and AWS_REGION are set." , err = True )
671674
672675 # Get GitHub tokens - CLI option takes precedence over environment
@@ -711,12 +714,15 @@ def batch_analyze(
711714 err = True ,
712715 )
713716
714- # Load prompt
715- try :
716- prompt_text = load_prompt (prompt_file )
717- except FileNotFoundError as e :
718- typer .echo (f"Error: { e } " , err = True )
719- raise typer .Exit (1 )
717+ # Load prompt (skip when fetch-only)
718+ if not fetch_only :
719+ try :
720+ prompt_text = load_prompt (prompt_file )
721+ except FileNotFoundError as e :
722+ typer .echo (f"Error: { e } " , err = True )
723+ raise typer .Exit (1 )
724+ else :
725+ prompt_text = None
720726
721727 # Get PR URLs
722728 if input_file :
@@ -785,6 +791,14 @@ def batch_analyze(
785791 since_override = since_override ,
786792 )
787793
794+ # Fetch-only mode: save to cache and exit
795+ if fetch_only :
796+ if not cache_file :
797+ typer .echo ("Error: --cache is required with --fetch-only" , err = True )
798+ raise typer .Exit (1 )
799+ typer .echo (f"✓ Fetched { len (pr_urls )} PR URLs to cache: { cache_file } " , err = True )
800+ return
801+
788802 # Create analyzer function with progress callback
789803 def progress_msg (msg : str ) -> None :
790804 """Display progress messages."""
0 commit comments