@@ -65,24 +65,29 @@ def _check_git_cli_installed() -> bool:
6565def configure_github_repo (
6666 directory : str | Path ,
6767 repo_name : str ,
68+ visibility : Literal ["private" , "public" ] = "private"
6869) -> bool :
6970 """
7071 Configure a Git repository locally and optionally on GitHub with specified branch protections.
7172
7273 Args:
7374 directory: Directory where the repository will be created or updated
7475 repo_name: Name of the repository
76+ visibility: Whether to upload to github as a public or private repo
7577
7678 Returns:
7779 bool: True if configuration was successful, False otherwise
7880 """
7981 try :
80- if not _check_gh_cli_installed_authenticated ():
81- raise RuntimeError (
82- "gh CLI is required but not installed or not authenticated. "
83- "Try installing and running `gh auth login`."
84- )
85-
82+ subprocess .run ("gh --version" , shell = True , check = True , capture_output = True )
83+ except subprocess .CalledProcessError :
84+ raise RuntimeError ("GitHub CLI is not installed. Please install and try again." )
85+ try :
86+ subprocess .run ("gh auth status" , shell = True , check = True , capture_output = True )
87+ except subprocess .CalledProcessError :
88+ raise RuntimeError ("GitHub CLI not authenticated. Please run `gh auth login` and try again." )
89+
90+ try :
8691 # GitHub operations
8792 github_username = _gh ("api user -q .login" , capture_output = True , text = True ).stdout .strip ()
8893
@@ -92,7 +97,7 @@ def configure_github_repo(
9297 if not init_local_git_repo (directory ):
9398 return False
9499 _gh (
95- f"repo create { repo_name } --private --source=. --remote=origin --push"
100+ f"repo create { repo_name } --{ visibility } --source=. --remote=origin --push"
96101 )
97102 else :
98103 remote_url = _get_gh_remote_url (github_username , repo_name )
@@ -120,16 +125,6 @@ def _gh(command: str, **kwargs) -> subprocess.CompletedProcess:
120125 """Run a GitHub CLI command and return the result."""
121126 return subprocess .run (f"gh { command } " , shell = True , check = True , ** kwargs )
122127
123-
124- def _check_gh_cli_installed_authenticated () -> bool :
125- """Check if gh CLI is installed and authenticated."""
126- try :
127- subprocess .run ("gh --version" , shell = True , check = True , capture_output = True )
128- subprocess .run ("gh auth status" , shell = True , check = True , capture_output = True )
129- return True
130- except subprocess .CalledProcessError :
131- return False
132-
133128def _get_gh_remote_url (github_username : str , repo_name : str ) -> Literal ["https" , "ssh" ]:
134129 """Returns whether the github protocol is https or ssh from user's config"""
135130 try :
0 commit comments