Skip to content

Commit 6fbd4ed

Browse files
committed
Split git (github) into git (github public) and git (github private). Fixed tests to match. Set tests to use git (local) and none by default
1 parent d83e6b7 commit 6fbd4ed

File tree

6 files changed

+42
-27
lines changed

6 files changed

+42
-27
lines changed

ccds-help.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,15 +295,22 @@
295295
{
296296
"choice": "git (local)",
297297
"help": {
298-
"description": "Initialize a git repository locally.",
299-
"more_information": ""
298+
"description": "Initialize project as a local git repository.",
299+
"more_information": "[Git CLI](https://git-scm.com/downloads) Required"
300300
}
301301
},
302302
{
303-
"choice": "git (github)",
303+
"choice": "git (github private)",
304304
"help": {
305-
"description": "Initialize a git repository locally and upload to GitHub",
306-
"more_information": ""
305+
"description": "Initialize project and upload to GitHub as a **private** repo.",
306+
"more_information": "[Git CLI](https://git-scm.com/downloads) + [GitHub CLI](https://cli.github.com/) & [Auth](https://cli.github.com/manual/gh_auth_login) Required"
307+
}
308+
},
309+
{
310+
"choice": "git (github public)",
311+
"help": {
312+
"description": "Initialize project and upload to GitHub as a **public** repo.",
313+
"more_information": "[Git CLI](https://git-scm.com/downloads) + [GitHub CLI](https://cli.github.com/) & [Auth](https://cli.github.com/manual/gh_auth_login) Required"
307314
}
308315
}
309316
]

ccds.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"version_control": [
3333
"none",
3434
"git (local)",
35-
"git (github)"
35+
"git (github private)",
36+
"git (github public)"
3637
]
3738
}

ccds/hook_utils/configure_vcs.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,24 +65,29 @@ def _check_git_cli_installed() -> bool:
6565
def 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-
133128
def _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:

hooks/post_gen_project.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,22 @@
8383
generated_path.write_text("")
8484
# {% endif %}
8585

86+
#
87+
# VERSION CONTROL
88+
#
89+
8690
# {% if cookiecutter.version_control == "git (local)" %}
87-
init_local_git_repo(directory=Path.cwd(), _make_initial_commit=True)
88-
# {% elif cookiecutter.version_control == "git (github)" %}
91+
init_local_git_repo(directory=Path.cwd())
92+
# {% elif cookiecutter.version_control == "git (github private)" %}
93+
configure_github_repo(
94+
directory=Path.cwd(),
95+
repo_name="{{ cookiecutter.repo_name }}",
96+
visibility="private"
97+
)
98+
# {% elif cookiecutter.version_control == "git (github public)" %}
8999
configure_github_repo(
90100
directory=Path.cwd(),
91101
repo_name="{{ cookiecutter.repo_name }}",
92-
protection_type="main_and_dev",
102+
visibility="public"
93103
)
94104
# {% endif %}

tests/conftest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def config_generator(fast=False):
3939
],
4040
[("dependency_file", opt) for opt in cookiecutter_json["dependency_file"]],
4141
[("pydata_packages", opt) for opt in cookiecutter_json["pydata_packages"]],
42+
[("version_control", opt) for opt in ("none", "git (local)")]
43+
# TODO: Tests for "version_control": "git (github)"
4244
)
4345

4446
def _is_valid(config):

tests/test_creation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def verify_folders(root, config):
8080
if config["docs"] == "mkdocs":
8181
expected_dirs.add("docs/docs")
8282

83-
if config["version_control"] in ("git (local)", "git (github)"):
83+
if config["version_control"] in ("git (local)", "git (github public)", "git (github private)"):
8484
# Expected after `git init`
8585
expected_dirs.update(
8686
{

0 commit comments

Comments
 (0)