MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / resolveRepoMetadata

Function resolveRepoMetadata

website/src/lib/repo-provider.ts:157–209  ·  view source on GitHub ↗
(
  ref: RepoRef
)

Source from the content-addressed store, hash-verified

155
156/** Resolve default branch and latest commit SHA for a repository. */
157export async function resolveRepoMetadata(
158 ref: RepoRef
159): Promise<{ detectedBranch: string; latestCommitSha: string }> {
160 let detectedBranch = "main";
161 let latestCommitSha = "";
162
163 const headers = getAuthHeaders(ref);
164
165 try {
166 if (ref.provider === "github") {
167 const apiRes = await fetch(
168 `https://api.github.com/repos/${ref.owner}/${ref.repo}`,
169 { headers }
170 );
171 if (apiRes.ok) {
172 const apiData = await apiRes.json();
173 if (apiData?.default_branch) {
174 detectedBranch = apiData.default_branch;
175 }
176 }
177
178 const commitsRes = await fetch(
179 `https://api.github.com/repos/${ref.owner}/${ref.repo}/commits/${detectedBranch}`,
180 { headers }
181 );
182 if (commitsRes.ok) {
183 const commitsData = await commitsRes.json();
184 if (commitsData?.sha) {
185 latestCommitSha = commitsData.sha;
186 }
187 }
188 } else {
189 const projectPath = encodeURIComponent(ref.fullPath);
190 const apiRes = await fetch(
191 `https://gitlab.com/api/v4/projects/${projectPath}`,
192 { headers }
193 );
194 if (apiRes.ok) {
195 const apiData = await apiRes.json();
196 if (apiData?.default_branch) {
197 detectedBranch = apiData.default_branch;
198 }
199 if (apiData?.last_commit_id) {
200 latestCommitSha = apiData.last_commit_id;
201 }
202 }
203 }
204 } catch (err) {
205 console.warn(`[Explore] Failed to resolve branch metadata for ${ref.fullPath}:`, err);
206 }
207
208 return { detectedBranch, latestCommitSha };
209}
210
211export function getZipProxyUrl(ref: RepoRef, branch: string): string {
212 if (ref.provider === "gitlab") {

Callers 1

fetchRepositoryFilesFunction · 0.90

Calls 1

getAuthHeadersFunction · 0.85

Tested by

no test coverage detected