MCPcopy Index your code
hub / github.com/sourcebot-dev/sourcebot / getFiles

Function getFiles

packages/web/src/features/git/getFilesApi.ts:16–62  ·  view source on GitHub ↗
({ repoName, revisionName }: GetFilesRequest)

Source from the content-addressed store, hash-verified

14export type GetFilesResponse = z.infer<typeof getFilesResponseSchema>;
15
16export const getFiles = async ({ repoName, revisionName }: GetFilesRequest): Promise<GetFilesResponse | ServiceError> => sew(() =>
17 withOptionalAuth(async ({ org, prisma }) => {
18 const repo = await prisma.repo.findFirst({
19 where: {
20 name: repoName,
21 orgId: org.id,
22 },
23 });
24
25 if (!repo) {
26 return notFound();
27 }
28
29 const { path: repoPath } = getRepoPath(repo);
30
31 const git = simpleGit().cwd(repoPath);
32
33 let result: string;
34 try {
35 result = await git.raw([
36 // Disable quoting of non-ASCII characters in paths
37 '-c', 'core.quotePath=false',
38 'ls-tree',
39 revisionName,
40 // recursive
41 '-r',
42 // only return the names of the files
43 '--name-only',
44 ]);
45 } catch (error) {
46 logger.error('git ls-tree failed.', { error });
47 return unexpectedError('git ls-tree command failed.');
48 }
49
50 const paths = result.split('\n').filter(line => line.trim());
51
52 const files: FileTreeItem[] = paths.map(path => {
53 const name = path.split('/').pop() ?? '';
54 return {
55 type: 'blob',
56 path,
57 name,
58 }
59 });
60
61 return files;
62 }));

Callers 1

route.tsFile · 0.90

Calls 5

sewFunction · 0.90
withOptionalAuthFunction · 0.90
notFoundFunction · 0.90
getRepoPathFunction · 0.90
unexpectedErrorFunction · 0.90

Tested by

no test coverage detected