55
66from server .models import IngestErrorResponse , IngestRequest , IngestSuccessResponse
77from server .query_processor import process_query
8+ from server .server_config import DEFAULT_MAX_FILE_SIZE_KB
89from server .server_utils import limiter
910
1011router = APIRouter ()
@@ -64,7 +65,6 @@ async def api_ingest(
6465 # Handle validation errors with 400 status code
6566 error_response = IngestErrorResponse (
6667 error = f"Validation error: { ve !s} " ,
67- repo_url = ingest_request .input_text ,
6868 )
6969 return JSONResponse (
7070 status_code = status .HTTP_400_BAD_REQUEST ,
@@ -75,7 +75,83 @@ async def api_ingest(
7575 # Handle unexpected errors with 500 status code
7676 error_response = IngestErrorResponse (
7777 error = f"Internal server error: { exc !s} " ,
78- repo_url = ingest_request .input_text ,
78+ )
79+ return JSONResponse (
80+ status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
81+ content = error_response .model_dump (),
82+ )
83+
84+
85+ @router .get (
86+ "/api/{user}/{repository}" ,
87+ responses = {
88+ status .HTTP_200_OK : {"model" : IngestSuccessResponse , "description" : "Successful ingestion" },
89+ status .HTTP_400_BAD_REQUEST : {"model" : IngestErrorResponse , "description" : "Bad request or processing error" },
90+ status .HTTP_500_INTERNAL_SERVER_ERROR : {"model" : IngestErrorResponse , "description" : "Internal server error" },
91+ },
92+ )
93+ @limiter .limit ("10/minute" )
94+ async def api_ingest_get (
95+ request : Request , # noqa: ARG001
96+ user : str ,
97+ repository : str ,
98+ max_file_size : int = DEFAULT_MAX_FILE_SIZE_KB ,
99+ pattern_type : str = "exclude" ,
100+ pattern : str = "" ,
101+ token : str = "" ,
102+ ) -> JSONResponse :
103+ """Ingest a GitHub repository via GET and return processed content.
104+
105+ **This endpoint processes a GitHub repository by analyzing its structure and returning a summary**
106+ with the repository's content. The response includes file tree structure, processed content, and
107+ metadata about the ingestion. All ingestion parameters are optional and can be provided as query parameters.
108+
109+ **Path Parameters**
110+ - **user** (`str`): GitHub username or organization
111+ - **repository** (`str`): GitHub repository name
112+
113+ **Query Parameters**
114+ - **max_file_size** (`int`, optional): Maximum file size to include in the digest (default: 50 KB)
115+ - **pattern_type** (`str`, optional): Type of pattern to use ("include" or "exclude", default: "exclude")
116+ - **pattern** (`str`, optional): Pattern to include or exclude in the query (default: "")
117+ - **token** (`str`, optional): GitHub personal access token for private repositories (default: "")
118+
119+ **Returns**
120+ - **JSONResponse**: Success response with ingestion results or error response with appropriate HTTP status code
121+ """ # pylint: disable=unused-argument
122+ try :
123+ effective_input_text = f"{ user } /{ repository } "
124+ result = await process_query (
125+ input_text = effective_input_text ,
126+ slider_position = max_file_size ,
127+ pattern_type = pattern_type ,
128+ pattern = pattern ,
129+ token = token or None ,
130+ )
131+
132+ if isinstance (result , IngestErrorResponse ):
133+ return JSONResponse (
134+ status_code = status .HTTP_400_BAD_REQUEST ,
135+ content = result .model_dump (),
136+ )
137+
138+ return JSONResponse (
139+ status_code = status .HTTP_200_OK ,
140+ content = result .model_dump (),
141+ )
142+
143+ except ValueError as ve :
144+ error_response = IngestErrorResponse (
145+ error = f"Validation error: { ve !s} " ,
146+ )
147+ return JSONResponse (
148+ status_code = status .HTTP_400_BAD_REQUEST ,
149+ content = error_response .model_dump (),
150+ )
151+
152+ except Exception as exc :
153+ error_response = IngestErrorResponse (
154+ error = f"Internal server error: { exc !s} " ,
79155 )
80156 return JSONResponse (
81157 status_code = status .HTTP_500_INTERNAL_SERVER_ERROR ,
0 commit comments