({
projectId,
}: {
projectId: string;
})
| 2698 | | GitRepoFile; |
| 2699 | |
| 2700 | const getRepositoryDirectoryTree = async ({ |
| 2701 | projectId, |
| 2702 | }: { |
| 2703 | projectId: string; |
| 2704 | }): Promise<{ |
| 2705 | repositoryTree: FileTree; |
| 2706 | folderList: Record<string, string[]>; |
| 2707 | }> => { |
| 2708 | const project = await services.project.get(projectId); |
| 2709 | |
| 2710 | if (project && models.project.isEmptyGitProject(project)) { |
| 2711 | return { |
| 2712 | repositoryTree: { |
| 2713 | id: '', |
| 2714 | name: 'Repository', |
| 2715 | type: 'root', |
| 2716 | children: [], |
| 2717 | }, |
| 2718 | folderList: {}, |
| 2719 | }; |
| 2720 | } |
| 2721 | |
| 2722 | const gitRepository = await getGitRepository({ projectId }); |
| 2723 | const fs = await getGitFSClient({ projectId, gitRepositoryId: gitRepository._id }); |
| 2724 | |
| 2725 | const rootContents = await fs.promises.readdir(GIT_CLONE_DIR); |
| 2726 | |
| 2727 | const folderList: Record<string, string[]> = { |
| 2728 | '': rootContents, |
| 2729 | }; |
| 2730 | |
| 2731 | const recursivelyGetDirectoryTree = async (directoryContents: string[], parentPath: string) => { |
| 2732 | const tree: (GitRepoDirectory | GitRepoFile)[] = await Promise.all( |
| 2733 | directoryContents.map(async (file: string) => { |
| 2734 | const fileOrDirPath = path.join(parentPath, file); |
| 2735 | const stats = await fs.promises.lstat(fileOrDirPath); |
| 2736 | if (await stats.isDirectory()) { |
| 2737 | const subDirectoryContents = await fs.promises.readdir(fileOrDirPath); |
| 2738 | folderList[fileOrDirPath] = subDirectoryContents; |
| 2739 | return { |
| 2740 | id: fileOrDirPath, |
| 2741 | name: file, |
| 2742 | type: 'directory', |
| 2743 | children: await recursivelyGetDirectoryTree(subDirectoryContents, fileOrDirPath), |
| 2744 | }; |
| 2745 | } |
| 2746 | return { |
| 2747 | id: fileOrDirPath, |
| 2748 | name: file, |
| 2749 | type: 'file', |
| 2750 | }; |
| 2751 | }), |
| 2752 | ); |
| 2753 | |
| 2754 | return tree; |
| 2755 | }; |
| 2756 | |
| 2757 | const tree = await recursivelyGetDirectoryTree(rootContents, GIT_CLONE_DIR); |
no test coverage detected