Process a query by parsing input, cloning a repository, and generating a summary. Handle user input, process Git repository data, and prepare a response for rendering a template with the processed results or an error message. Parameters ---------- input_text : str Input
(
input_text: str,
max_file_size: int,
pattern_type: PatternType,
pattern: str,
token: str | None = None,
)
| 227 | |
| 228 | |
| 229 | async def process_query( |
| 230 | input_text: str, |
| 231 | max_file_size: int, |
| 232 | pattern_type: PatternType, |
| 233 | pattern: str, |
| 234 | token: str | None = None, |
| 235 | ) -> IngestResponse: |
| 236 | """Process a query by parsing input, cloning a repository, and generating a summary. |
| 237 | |
| 238 | Handle user input, process Git repository data, and prepare |
| 239 | a response for rendering a template with the processed results or an error message. |
| 240 | |
| 241 | Parameters |
| 242 | ---------- |
| 243 | input_text : str |
| 244 | Input text provided by the user, typically a Git repository URL or slug. |
| 245 | max_file_size : int |
| 246 | Max file size in KB to be include in the digest. |
| 247 | pattern_type : PatternType |
| 248 | Type of pattern to use (either "include" or "exclude") |
| 249 | pattern : str |
| 250 | Pattern to include or exclude in the query, depending on the pattern type. |
| 251 | token : str | None |
| 252 | GitHub personal access token (PAT) for accessing private repositories. |
| 253 | |
| 254 | Returns |
| 255 | ------- |
| 256 | IngestResponse |
| 257 | A union type, corresponding to IngestErrorResponse or IngestSuccessResponse |
| 258 | |
| 259 | Raises |
| 260 | ------ |
| 261 | RuntimeError |
| 262 | If the commit hash is not found (should never happen). |
| 263 | |
| 264 | """ |
| 265 | if token: |
| 266 | validate_github_token(token) |
| 267 | |
| 268 | try: |
| 269 | query = await parse_remote_repo(input_text, token=token) |
| 270 | except Exception as exc: |
| 271 | logger.warning("Failed to parse remote repository", extra={"input_text": input_text, "error": str(exc)}) |
| 272 | return IngestErrorResponse(error=str(exc)) |
| 273 | |
| 274 | query.url = cast("str", query.url) |
| 275 | query.max_file_size = max_file_size * 1024 # Convert to bytes since we currently use KB in higher levels |
| 276 | query.ignore_patterns, query.include_patterns = process_patterns( |
| 277 | exclude_patterns=pattern if pattern_type == PatternType.EXCLUDE else None, |
| 278 | include_patterns=pattern if pattern_type == PatternType.INCLUDE else None, |
| 279 | ) |
| 280 | |
| 281 | # Check if digest already exists on S3 before cloning |
| 282 | s3_response = await _check_s3_cache( |
| 283 | query=query, |
| 284 | input_text=input_text, |
| 285 | max_file_size=max_file_size, |
| 286 | pattern_type=pattern_type.value, |
no test coverage detected