33from __future__ import annotations
44
55from pathlib import Path
6- from typing import Any , cast
6+ from typing import cast
77
88from gitingest .clone import clone_repo
99from gitingest .ingestion import ingest_query
1010from gitingest .query_parser import IngestionQuery , parse_query
1111from gitingest .utils .git_utils import validate_github_token
12+ from server .models import IngestErrorResponse , IngestResponse , IngestSuccessResponse
1213from server .server_config import (
13- DEFAULT_FILE_SIZE_KB ,
14- EXAMPLE_REPOS ,
14+ DEFAULT_MAX_FILE_SIZE_KB ,
1515 MAX_DISPLAY_SIZE ,
1616)
1717from server .server_utils import Colors , log_slider_to_size
@@ -23,7 +23,7 @@ async def process_query(
2323 pattern_type : str = "exclude" ,
2424 pattern : str = "" ,
2525 token : str | None = None ,
26- ) -> dict [ str , Any ] :
26+ ) -> IngestResponse :
2727 """Process a query by parsing input, cloning a repository, and generating a summary.
2828
2929 Handle user input, process Git repository data, and prepare
@@ -44,8 +44,8 @@ async def process_query(
4444
4545 Returns
4646 -------
47- dict[str, Any]
48- A dictionary containing the processed results or an error message.
47+ IngestResponse
48+ A union type, corresponding to IngestErrorResponse or IngestSuccessResponse
4949
5050 Raises
5151 ------
@@ -68,16 +68,8 @@ async def process_query(
6868
6969 max_file_size = log_slider_to_size (slider_position )
7070
71- context = {
72- "repo_url" : input_text ,
73- "examples" : EXAMPLE_REPOS ,
74- "default_file_size" : slider_position ,
75- "pattern_type" : pattern_type ,
76- "pattern" : pattern ,
77- "token" : token ,
78- }
79-
8071 query : IngestionQuery | None = None
72+ short_repo_url = ""
8173
8274 try :
8375 query = await parse_query (
@@ -91,7 +83,7 @@ async def process_query(
9183 query .ensure_url ()
9284
9385 # Sets the "<user>/<repo>" for the page title
94- context [ " short_repo_url" ] = f"{ query .user_name } /{ query .repo_name } "
86+ short_repo_url = f"{ query .user_name } /{ query .repo_name } "
9587
9688 clone_config = query .extract_clone_config ()
9789 await clone_repo (clone_config , token = token )
@@ -110,10 +102,10 @@ async def process_query(
110102 print (f"{ Colors .BROWN } WARN{ Colors .END } : { Colors .RED } <- { Colors .END } " , end = "" )
111103 print (f"{ Colors .RED } { exc } { Colors .END } " )
112104
113- context [ "error" ] = f"Error: { exc } "
114- if "405" in str (exc ):
115- context [ "error_message" ] = "Repository not found. Please make sure it is public."
116- return context
105+ return IngestErrorResponse (
106+ error = "Repository not found. Please make sure it is public." if "405" in str (exc ) else "" ,
107+ repo_url = short_repo_url ,
108+ )
117109
118110 if len (content ) > MAX_DISPLAY_SIZE :
119111 content = (
@@ -132,16 +124,17 @@ async def process_query(
132124 summary = summary ,
133125 )
134126
135- context .update (
136- {
137- "summary" : summary ,
138- "tree" : tree ,
139- "content" : content ,
140- },
127+ return IngestSuccessResponse (
128+ repo_url = input_text ,
129+ short_repo_url = short_repo_url ,
130+ summary = summary ,
131+ tree = tree ,
132+ content = content ,
133+ default_max_file_size = slider_position ,
134+ pattern_type = pattern_type ,
135+ pattern = pattern ,
141136 )
142137
143- return context
144-
145138
146139def _print_query (url : str , max_file_size : int , pattern_type : str , pattern : str ) -> None :
147140 """Print a formatted summary of the query details for debugging.
@@ -159,7 +152,7 @@ def _print_query(url: str, max_file_size: int, pattern_type: str, pattern: str)
159152
160153 """
161154 print (f"{ Colors .WHITE } { url :<20} { Colors .END } " , end = "" )
162- if int (max_file_size / 1024 ) != DEFAULT_FILE_SIZE_KB :
155+ if int (max_file_size / 1024 ) != DEFAULT_MAX_FILE_SIZE_KB :
163156 print (
164157 f" | { Colors .YELLOW } Size: { int (max_file_size / 1024 )} kb{ Colors .END } " ,
165158 end = "" ,
0 commit comments