* Fetches the full recursive tree for a branch.
( accessToken: string, owner: string, repo: string, branch: string )
| 80 | * Fetches the full recursive tree for a branch. |
| 81 | */ |
| 82 | async function fetchTree( |
| 83 | accessToken: string, |
| 84 | owner: string, |
| 85 | repo: string, |
| 86 | branch: string |
| 87 | ): Promise<TreeItem[]> { |
| 88 | const url = `${GITHUB_API_URL}/repos/${owner}/${repo}/git/trees/${encodeURIComponent(branch)}?recursive=1` |
| 89 | |
| 90 | const response = await fetchWithRetry(url, { |
| 91 | method: 'GET', |
| 92 | headers: { |
| 93 | Accept: 'application/vnd.github+json', |
| 94 | Authorization: `Bearer ${accessToken}`, |
| 95 | 'X-GitHub-Api-Version': '2022-11-28', |
| 96 | }, |
| 97 | }) |
| 98 | |
| 99 | if (!response.ok) { |
| 100 | const errorText = await response.text() |
| 101 | logger.error('Failed to fetch GitHub tree', { status: response.status, error: errorText }) |
| 102 | throw new Error(`Failed to fetch repository tree: ${response.status}`) |
| 103 | } |
| 104 | |
| 105 | const data = await response.json() |
| 106 | |
| 107 | if (data.truncated) { |
| 108 | logger.warn('GitHub tree was truncated — some files may be missing', { owner, repo, branch }) |
| 109 | } |
| 110 | |
| 111 | return (data.tree || []).filter((item: TreeItem) => item.type === 'blob') |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * Fetches blob content via the Git Blobs API. Used as a fallback when the |
no test coverage detected