feat: +SummarizeCode, refactor project_name

This commit is contained in:
莘权 马 2023-12-04 23:04:07 +08:00
parent 838b3cfcc8
commit dac4be4b3e
12 changed files with 224 additions and 103 deletions

View file

@ -151,6 +151,17 @@ class FileRepository:
relative_files[str(rf)] = ct
return relative_files
@property
def all_files(self) -> List:
"""Get a dictionary of all files in the repository.
The dictionary includes file paths relative to the current FileRepository.
:return: A dictionary where keys are file paths and values are file information.
:rtype: List
"""
return self._git_repo.get_files(relative_path=self._relative_path)
def get_change_dir_files(self, dir: Path | str) -> List:
"""Get the files in a directory that have changed.

View file

@ -11,7 +11,7 @@ from __future__ import annotations
import shutil
from enum import Enum
from pathlib import Path
from typing import Dict
from typing import Dict, List
from git.repo import Repo
from git.repo.fun import is_git_dir
@ -200,6 +200,32 @@ class GitRepository:
logger.info(f"Rename directory {str(self.workdir)} to {str(new_path)}")
self._repository = Repo(new_path)
def get_files(self, relative_path: Path | str) -> List:
"""Retrieve a list of files in the specified relative path.
The method returns a list of file paths relative to the current FileRepository.
:param relative_path: The relative path within the repository.
:type relative_path: Path or str
:return: A list of file paths in the specified directory.
:rtype: List[str]
"""
try:
relative_path = Path(relative_path).relative_to(self.workdir)
except ValueError:
relative_path = Path(relative_path)
files = []
try:
directory_path = Path(self.workdir) / relative_path
for file_path in directory_path.iterdir():
if file_path.is_file():
rpath = file_path.relative_to(directory_path)
files.append(str(rpath))
except Exception as e:
logger.error(f"Error: {e}")
return files
if __name__ == "__main__":
path = DEFAULT_WORKSPACE_ROOT / "git"