migratron / src /services /githubService.ts
amrithanandini's picture
updated UI
6d6193f
export interface GitTreeNode {
path: string;
mode: string;
type: 'tree' | 'blob';
sha: string;
size?: number;
url: string;
}
export interface GitTreeResponse {
sha: string;
url: string;
tree: GitTreeNode[];
truncated: boolean;
}
export const githubService = {
/**
* Fetch the full recursive file tree for a repository at a specific commit.
*/
async fetchTree(repoFullName: string, commitHash: string): Promise<GitTreeNode[]> {
const response = await fetch(`https://api.github.com/repos/${repoFullName}/git/trees/${commitHash}?recursive=1`);
if (!response.ok) {
throw new Error(`Failed to fetch tree: ${response.statusText}`);
}
const data: GitTreeResponse = await response.json();
return data.tree;
},
/**
* Fetch the raw content of a specific file at a specific commit.
*/
async fetchFileContent(repoFullName: string, commitHash: string, filePath: string): Promise<string> {
const response = await fetch(`https://raw.githubusercontent.com/${repoFullName}/${commitHash}/${filePath}`);
if (!response.ok) {
throw new Error(`Failed to fetch file content: ${response.statusText}`);
}
return await response.text();
}
};