MCPcopy
hub / github.com/opentrace/opentrace / fetchGitHubTree

Function fetchGitHubTree

ui/src/components/pipeline/__tests__/github.test.ts:55–78  ·  view source on GitHub ↗

* Fetch the full recursive tree from GitHub's Git Trees API. * Returns only blob entries (files, not directories).

(
  owner: string,
  repo: string,
  ref: string,
)

Source from the content-addressed store, hash-verified

53 * Returns only blob entries (files, not directories).
54 */
55async function fetchGitHubTree(
56 owner: string,
57 repo: string,
58 ref: string,
59): Promise<{ files: GitHubTreeEntry[]; sha: string }> {
60 const url = `https://api.github.com/repos/${owner}/${repo}/git/trees/${ref}?recursive=1`;
61 const headers: Record<string, string> = {
62 Accept: 'application/vnd.github+json',
63 'User-Agent': 'opentrace-pipeline-test',
64 };
65 // Use GITHUB_TOKEN if available (avoids rate limits in CI)
66 if (process.env.GITHUB_TOKEN) {
67 headers.Authorization = `Bearer ${process.env.GITHUB_TOKEN}`;
68 }
69
70 const res = await fetch(url, { headers });
71 if (!res.ok) {
72 throw new Error(`GitHub API ${res.status}: ${await res.text()}`);
73 }
74
75 const data: GitHubTreeResponse = await res.json();
76 const files = data.tree.filter((e) => e.type === 'blob');
77 return { files, sha: data.sha };
78}
79
80describe.skipIf(SKIP)('github: grafana/grafana', () => {
81 let repoTree: RepoTree;

Callers 1

github.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected