24
24
class RemoteRepoOperator (RepoOperator ):
25
25
"""A wrapper around GitPython to make it easier to interact with a cloned lowside repo."""
26
26
27
+ # __init__ attributes
27
28
repo_config : RepoConfig
28
29
base_dir : str
30
+
31
+ # lazy attributes
29
32
_remote_git_repo : GitRepoClient | None = None
30
33
_codeowners_parser : CodeOwnersParser | None = None
31
34
_default_branch : str | None = None
32
- bot_commit : bool = True
33
35
34
36
# TODO: allow setting the access scope level of the lowside repo (currently it's always WRITE)
35
37
def __init__ (
@@ -38,9 +40,9 @@ def __init__(
38
40
base_dir : str = "/tmp" ,
39
41
setup_option : SetupOption = SetupOption .PULL_OR_CLONE ,
40
42
shallow : bool = True ,
41
- bot_commit : bool = True ,
43
+ github_type : GithubType = GithubType . GithubEnterprise ,
42
44
) -> None :
43
- super ().__init__ (repo_config = repo_config , base_dir = base_dir , bot_commit = bot_commit )
45
+ super ().__init__ (repo_config = repo_config , base_dir = base_dir )
44
46
self .setup_repo_dir (setup_option = setup_option , shallow = shallow )
45
47
46
48
####################################################################################################################
@@ -50,8 +52,7 @@ def __init__(
50
52
@property
51
53
def remote_git_repo (self ) -> GitRepoClient :
52
54
if not self ._remote_git_repo :
53
- # NOTE: local repo operator by default points at lowside (i.e. origin remote is lowside remote)
54
- self ._remote_git_repo = GitRepoClient (self .repo_config , github_type = GithubType .GithubEnterprise , access_scope = GithubScope .WRITE )
55
+ self ._remote_git_repo = GitRepoClient (self .repo_config , access_scope = GithubScope .WRITE )
55
56
return self ._remote_git_repo
56
57
57
58
@property
@@ -69,27 +70,31 @@ def codeowners_parser(self) -> CodeOwnersParser | None:
69
70
####################################################################################################################
70
71
# SET UP
71
72
####################################################################################################################
73
+
72
74
@override
73
75
def pull_repo (self ) -> None :
74
76
"""Pull the latest commit down to an existing local repo"""
75
77
pull_repo (repo = self .repo_config , path = self .base_dir )
76
78
77
- def clone_or_pull_repo (self ) -> None :
79
+ def clone_repo (self , shallow : bool = True ) -> None :
80
+ clone_repo (repo = self .repo_config , path = self .base_dir , shallow = shallow )
81
+
82
+ def clone_or_pull_repo (self , shallow : bool = True ) -> None :
78
83
"""If repo exists, pulls changes. otherwise, clones the repo."""
79
84
# 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
80
85
if self .repo_exists ():
81
86
self .clean_repo ()
82
- clone_or_pull_repo (self .repo_config , path = self .base_dir , shallow = True )
87
+ clone_or_pull_repo (self .repo_config , path = self .base_dir , shallow = shallow )
83
88
84
89
def setup_repo_dir (self , setup_option : SetupOption = SetupOption .PULL_OR_CLONE , shallow : bool = True ) -> None :
85
90
os .makedirs (self .base_dir , exist_ok = True )
86
91
os .chdir (self .base_dir )
87
92
if setup_option is SetupOption .CLONE :
88
93
# if repo exists delete, then clone, else clone
89
- clone_repo (repo = self . repo_config , path = self . base_dir , shallow = shallow )
94
+ clone_repo (shallow = shallow )
90
95
elif setup_option is SetupOption .PULL_OR_CLONE :
91
96
# if repo exists, pull changes, else clone
92
- self .clone_or_pull_repo ()
97
+ self .clone_or_pull_repo (shallow = shallow )
93
98
elif setup_option is SetupOption .SKIP :
94
99
if not self .repo_exists ():
95
100
logger .warning (f"Valid git repo does not exist at { self .repo_path } . Cannot skip setup with SetupOption.SKIP." )
0 commit comments