Return the file tree and README content for a local repository.
(path: str = Query(None, description="Path to local repository"))
| 274 | |
| 275 | @app.get("/local_repo/structure") |
| 276 | async def get_local_repo_structure(path: str = Query(None, description="Path to local repository")): |
| 277 | """Return the file tree and README content for a local repository.""" |
| 278 | if not path: |
| 279 | return JSONResponse( |
| 280 | status_code=400, |
| 281 | content={"error": "No path provided. Please provide a 'path' query parameter."} |
| 282 | ) |
| 283 | |
| 284 | if not os.path.isdir(path): |
| 285 | return JSONResponse( |
| 286 | status_code=404, |
| 287 | content={"error": f"Directory not found: {path}"} |
| 288 | ) |
| 289 | |
| 290 | try: |
| 291 | logger.info(f"Processing local repository at: {path}") |
| 292 | file_tree_lines = [] |
| 293 | readme_content = "" |
| 294 | |
| 295 | for root, dirs, files in os.walk(path): |
| 296 | # Exclude hidden dirs/files and virtual envs |
| 297 | dirs[:] = [d for d in dirs if not d.startswith('.') and d != '__pycache__' and d != 'node_modules' and d != '.venv'] |
| 298 | for file in files: |
| 299 | if file.startswith('.') or file == '__init__.py' or file == '.DS_Store': |
| 300 | continue |
| 301 | rel_dir = os.path.relpath(root, path) |
| 302 | rel_file = os.path.join(rel_dir, file) if rel_dir != '.' else file |
| 303 | file_tree_lines.append(rel_file) |
| 304 | # Find README.md (case-insensitive) |
| 305 | if file.lower() == 'readme.md' and not readme_content: |
| 306 | try: |
| 307 | with open(os.path.join(root, file), 'r', encoding='utf-8') as f: |
| 308 | readme_content = f.read() |
| 309 | except Exception as e: |
| 310 | logger.warning(f"Could not read README.md: {str(e)}") |
| 311 | readme_content = "" |
| 312 | |
| 313 | file_tree_str = '\n'.join(sorted(file_tree_lines)) |
| 314 | return {"file_tree": file_tree_str, "readme": readme_content} |
| 315 | except Exception as e: |
| 316 | logger.error(f"Error processing local repository: {str(e)}") |
| 317 | return JSONResponse( |
| 318 | status_code=500, |
| 319 | content={"error": f"Error processing local repository: {str(e)}"} |
| 320 | ) |
| 321 | |
| 322 | def generate_markdown_export(repo_url: str, pages: List[WikiPage]) -> str: |
| 323 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected