Fetch the repository file tree (first 100 files).
(
client, headers: dict, full_name: str, branch: str,
)
| 98 | |
| 99 | |
| 100 | async def _fetch_file_tree( |
| 101 | client, headers: dict, full_name: str, branch: str, |
| 102 | ) -> list[str]: |
| 103 | """Fetch the repository file tree (first 100 files).""" |
| 104 | await _limiter.acquire() |
| 105 | try: |
| 106 | resp = await client.get( |
| 107 | f"{GITHUB_API}/repos/{full_name}/git/trees/{branch}", |
| 108 | params={"recursive": "1"}, |
| 109 | headers=headers, |
| 110 | ) |
| 111 | if resp.status_code != 200: |
| 112 | return [] |
| 113 | data = resp.json() |
| 114 | # Return only Python files and key config files, limit to 100 |
| 115 | paths = [] |
| 116 | for item in data.get("tree", []): |
| 117 | p = item.get("path", "") |
| 118 | if item.get("type") != "blob": |
| 119 | continue |
| 120 | if p.endswith((".py", ".yaml", ".yml", ".toml", ".cfg", ".sh", ".md")): |
| 121 | paths.append(p) |
| 122 | if len(paths) >= 100: |
| 123 | break |
| 124 | return paths |
| 125 | except Exception as e: |
| 126 | logger.debug("Failed to fetch tree for %s: %s", full_name, e) |
| 127 | return [] |
| 128 | |
| 129 | |
| 130 | async def _fetch_readme(client, headers: dict, full_name: str) -> str: |
no test coverage detected