From 1427dee300ee15d75e00bea8c57e11b5a92d3ee5 Mon Sep 17 00:00:00 2001 From: Christine Wang Date: Thu, 23 Jan 2025 19:22:23 -0800 Subject: [PATCH] chore: pass shallow param through --- .../git/repo_operator/remote_repo_operator.py | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/codegen/git/repo_operator/remote_repo_operator.py b/src/codegen/git/repo_operator/remote_repo_operator.py index 8ac6881ac..36187abf0 100644 --- a/src/codegen/git/repo_operator/remote_repo_operator.py +++ b/src/codegen/git/repo_operator/remote_repo_operator.py @@ -24,12 +24,14 @@ class RemoteRepoOperator(RepoOperator): """A wrapper around GitPython to make it easier to interact with a cloned lowside repo.""" + # __init__ attributes repo_config: RepoConfig base_dir: str + + # lazy attributes _remote_git_repo: GitRepoClient | None = None _codeowners_parser: CodeOwnersParser | None = None _default_branch: str | None = None - bot_commit: bool = True # TODO: allow setting the access scope level of the lowside repo (currently it's always WRITE) def __init__( @@ -38,9 +40,9 @@ def __init__( base_dir: str = "/tmp", setup_option: SetupOption = SetupOption.PULL_OR_CLONE, shallow: bool = True, - bot_commit: bool = True, + github_type: GithubType = GithubType.GithubEnterprise, ) -> None: - super().__init__(repo_config=repo_config, base_dir=base_dir, bot_commit=bot_commit) + super().__init__(repo_config=repo_config, base_dir=base_dir) self.setup_repo_dir(setup_option=setup_option, shallow=shallow) #################################################################################################################### @@ -50,8 +52,7 @@ def __init__( @property def remote_git_repo(self) -> GitRepoClient: if not self._remote_git_repo: - # NOTE: local repo operator by default points at lowside (i.e. origin remote is lowside remote) - self._remote_git_repo = GitRepoClient(self.repo_config, github_type=GithubType.GithubEnterprise, access_scope=GithubScope.WRITE) + self._remote_git_repo = GitRepoClient(self.repo_config, access_scope=GithubScope.WRITE) return self._remote_git_repo @property @@ -69,27 +70,31 @@ def codeowners_parser(self) -> CodeOwnersParser | None: #################################################################################################################### # SET UP #################################################################################################################### + @override def pull_repo(self) -> None: """Pull the latest commit down to an existing local repo""" pull_repo(repo=self.repo_config, path=self.base_dir) - def clone_or_pull_repo(self) -> None: + def clone_repo(self, shallow: bool = True) -> None: + clone_repo(repo=self.repo_config, path=self.base_dir, shallow=shallow) + + def clone_or_pull_repo(self, shallow: bool = True) -> None: """If repo exists, pulls changes. otherwise, clones the repo.""" # TODO(CG-7804): if repo is not valid we should delete it and re-clone. maybe we can create a pull_repo util + use the existing clone_repo util if self.repo_exists(): self.clean_repo() - clone_or_pull_repo(self.repo_config, path=self.base_dir, shallow=True) + clone_or_pull_repo(self.repo_config, path=self.base_dir, shallow=shallow) def setup_repo_dir(self, setup_option: SetupOption = SetupOption.PULL_OR_CLONE, shallow: bool = True) -> None: os.makedirs(self.base_dir, exist_ok=True) os.chdir(self.base_dir) if setup_option is SetupOption.CLONE: # if repo exists delete, then clone, else clone - clone_repo(repo=self.repo_config, path=self.base_dir, shallow=shallow) + clone_repo(shallow=shallow) elif setup_option is SetupOption.PULL_OR_CLONE: # if repo exists, pull changes, else clone - self.clone_or_pull_repo() + self.clone_or_pull_repo(shallow=shallow) elif setup_option is SetupOption.SKIP: if not self.repo_exists(): logger.warning(f"Valid git repo does not exist at {self.repo_path}. Cannot skip setup with SetupOption.SKIP.")