@@ -65,19 +65,13 @@ def _check_git_cli_installed() -> bool:
6565def configure_github_repo (
6666 directory : str | Path ,
6767 repo_name : str ,
68- protection_type : Literal ["none" , "main" , "main_and_dev" ],
6968) -> bool :
7069 """
7170 Configure a Git repository locally and optionally on GitHub with specified branch protections.
7271
7372 Args:
7473 directory: Directory where the repository will be created or updated
7574 repo_name: Name of the repository
76- protection_type: Type of branch protection to apply:
77- - "none": No branch protection
78- - "main": Protected main branch
79- - "main_and_dev": Protected main and dev branches
80- no_github: If True, skips GitHub operations and only sets up local repository
8175
8276 Returns:
8377 bool: True if configuration was successful, False otherwise
@@ -88,63 +82,30 @@ def configure_github_repo(
8882 "gh CLI is required but not installed or not authenticated. "
8983 "Try installing and running `gh auth login`."
9084 )
91-
92- # Initialize local repository
93- if not init_local_git_repo (directory ):
94- return False
95-
96- # # Create dev branch if needed
97- # if protection_type == "main_and_dev":
98- # if not _branch_exists("dev"):
99- # _git("branch dev")
100-
101- # # Add semantic versioning tag if it doesn't exist
102- # if not _tag_exists("v0.1.0"):
103- # _git("tag -a v0.1.0 -m 'Initial version'")
104-
105- # # Create dev branch if needed
106- # if protection_type == "main_and_dev":
107- # if not _branch_exists("dev"):
108- # _git("branch dev")
109-
85+
11086 # GitHub operations
11187 github_username = _gh ("api user -q .login" , capture_output = True , text = True ).stdout .strip ()
11288
11389 # Create or update GitHub repository
11490 if not _github_repo_exists (github_username , repo_name ):
91+ # Initialize local repository
92+ if not init_local_git_repo (directory ):
93+ return False
11594 _gh (
11695 f"repo create { repo_name } --private --source=. --remote=origin --push"
11796 )
11897 else :
11998 remote_url = _get_gh_remote_url (github_username , repo_name )
120- raise RuntimeError (f"Github repo already exists at { remote_url } " )
99+ raise RuntimeError (f"GitHub repo already exists at { remote_url } " )
121100 # TODO: Prompt user if they would like to set existing repo as origin.
122101 # remote_url = _get_gh_remote_url(github_username, repo_name)
123102 # try:
124103 # _git(f"remote set-url origin {remote_url}")
125104 # except subprocess.CalledProcessError:
126105 # _git(f"remote add origin {remote_url}")
127106
128- # Push branches and tags
107+ # Push to newly created origin
129108 _git ("push -u origin main" )
130- # _git("push --tags")
131-
132- # if _branch_exists("dev"):
133- # _git("push -u origin dev")
134-
135- # Set branch protections if repository is public
136- # is_public = _is_repo_public(github_username, repo_name)
137- # if is_public:
138- # if protection_type in ["main", "main_and_dev"]:
139- # _set_branch_protection(github_username, repo_name, "main")
140- # if protection_type == "main_and_dev":
141- # _set_branch_protection(github_username, repo_name, "dev")
142- # print("Branch protections set successfully.")
143- # else:
144- # print(
145- # "Warning: Branch protections can only be set for public repositories "
146- # "or with a GitHub Pro account."
147- # )
148109
149110 print ("Repository configuration complete on GitHub!" )
150111
0 commit comments