1313from codegen .git .clients .git_repo_client import GitRepoClient
1414from codegen .git .repo_operator .repo_operator import RepoOperator
1515from codegen .git .schemas .enums import FetchResult
16- from codegen .git .schemas .repo_config import BaseRepoConfig
16+ from codegen .git .schemas .repo_config import RepoConfig
1717from codegen .git .utils .clone_url import url_to_github
1818from codegen .git .utils .file_utils import create_files
1919
@@ -31,28 +31,21 @@ class LocalRepoOperator(RepoOperator):
3131 - Creating "fake" repos from a dictionary of files contents
3232 """
3333
34- _repo_path : str
35- _repo_name : str
3634 _git_cli : GitCLI
37- repo_config : BaseRepoConfig
3835 _github_api_key : str | None
3936 _remote_git_repo : GitRepoClient | None = None
4037
4138 def __init__ (
4239 self ,
43- repo_path : str , # full path to the repo
40+ repo_config : RepoConfig ,
4441 github_api_key : str | None = None ,
45- repo_config : BaseRepoConfig | None = None ,
4642 bot_commit : bool = False ,
4743 ) -> None :
48- self ._repo_path = repo_path
49- self ._repo_name = os .path .basename (repo_path )
5044 self ._github_api_key = github_api_key
5145 self ._remote_git_repo = None
46+ super ().__init__ (repo_config , bot_commit )
5247 os .makedirs (self .repo_path , exist_ok = True )
5348 GitCLI .init (self .repo_path )
54- repo_config = repo_config or BaseRepoConfig ()
55- super ().__init__ (repo_config , self .repo_path , bot_commit )
5649
5750 ####################################################################################################################
5851 # PROPERTIES
@@ -86,7 +79,7 @@ def remote_git_repo(self) -> GitRepoClient:
8679 # CLASS METHODS
8780 ####################################################################################################################
8881 @classmethod
89- def create_from_files (cls , repo_path : str , files : dict [str , str ], bot_commit : bool = True , repo_config : BaseRepoConfig = BaseRepoConfig () ) -> "LocalRepoOperator" :
82+ def create_from_files (cls , repo_path : str , files : dict [str , str ], bot_commit : bool = True ) -> "LocalRepoOperator" :
9083 """Used when you want to create a directory from a set of files and then create a LocalRepoOperator that points to that directory.
9184 Use cases:
9285 - Unit testing
@@ -96,14 +89,13 @@ def create_from_files(cls, repo_path: str, files: dict[str, str], bot_commit: bo
9689 Args:
9790 repo_path (str): The path to the directory to create.
9891 files (dict[str, str]): A dictionary of file names and contents to create in the directory.
99- repo_config (BaseRepoConfig): The configuration of the repo.
10092 """
10193 # Step 1: Create dir (if not exists) + files
10294 os .makedirs (repo_path , exist_ok = True )
10395 create_files (base_dir = repo_path , files = files )
10496
10597 # Step 2: Init git repo
106- op = cls (repo_path = repo_path , bot_commit = bot_commit , repo_config = repo_config )
98+ op = cls (repo_config = RepoConfig . from_repo_path ( repo_path ) , bot_commit = bot_commit )
10799 if op .stage_and_commit_all_changes ("[Codegen] initial commit" ):
108100 op .checkout_branch (None , create_if_missing = True )
109101 return op
@@ -118,7 +110,7 @@ def create_from_commit(cls, repo_path: str, commit: str, url: str, github_api_ke
118110 url (str): Git URL of the repository
119111 github_api_key (str | None): Optional GitHub API key for operations that need GitHub access
120112 """
121- op = cls (repo_path = repo_path , bot_commit = False , github_api_key = github_api_key )
113+ op = cls (repo_config = RepoConfig . from_repo_path ( repo_path ) , bot_commit = False , github_api_key = github_api_key )
122114 op .discard_changes ()
123115 if op .get_active_branch_or_commit () != commit :
124116 op .create_remote ("origin" , url )
@@ -149,7 +141,7 @@ def create_from_repo(cls, repo_path: str, url: str, github_api_key: str | None =
149141 remote_head = git_cli .remotes .origin .refs [git_cli .active_branch .name ].commit
150142 # If up to date, use existing repo
151143 if local_head .hexsha == remote_head .hexsha :
152- return cls (repo_path = repo_path , bot_commit = False , github_api_key = github_api_key )
144+ return cls (repo_config = RepoConfig . from_repo_path ( repo_path ) , bot_commit = False , github_api_key = github_api_key )
153145 except Exception :
154146 # If any git operations fail, fallback to fresh clone
155147 pass
@@ -166,20 +158,12 @@ def create_from_repo(cls, repo_path: str, url: str, github_api_key: str | None =
166158 # Initialize with the cloned repo
167159 git_cli = GitCLI (repo_path )
168160
169- return cls (repo_path = repo_path , bot_commit = False , github_api_key = github_api_key )
161+ return cls (repo_config = RepoConfig . from_repo_path ( repo_path ) , bot_commit = False , github_api_key = github_api_key )
170162
171163 ####################################################################################################################
172164 # PROPERTIES
173165 ####################################################################################################################
174166
175- @property
176- def repo_name (self ) -> str :
177- return self ._repo_name
178-
179- @property
180- def repo_path (self ) -> str :
181- return self ._repo_path
182-
183167 @property
184168 def codeowners_parser (self ) -> CodeOwnersParser | None :
185169 return None
0 commit comments