diff --git a/src/_nebari/subcommands/init.py b/src/_nebari/subcommands/init.py index 11a7f8ec1..743d30cb4 100644 --- a/src/_nebari/subcommands/init.py +++ b/src/_nebari/subcommands/init.py @@ -812,21 +812,9 @@ def guided_init_wizard(ctx: typer.Context, guided_init: str): qmark=qmark, ).unsafe_ask() - org_name = questionary.text( - f"Which user or organization will this repository live under? ({repo_url.format(git_provider=git_provider, org_name='', repo_name='')})", - qmark=qmark, - ).unsafe_ask() - - repo_name = questionary.text( - f"And what will the name of this repository be? ({repo_url.format(git_provider=git_provider, org_name=org_name, repo_name='')})", - qmark=qmark, - ).unsafe_ask() - - inputs.repository = repo_url.format( - git_provider=git_provider, org_name=org_name, repo_name=repo_name - ) - if git_provider == GitRepoEnum.github.value.lower(): + inputs.ci_provider = CiEnum.github_actions.value.lower() + inputs.repository_auto_provision = questionary.confirm( f"Would you like nebari to create a remote repository on {git_provider}?", default=False, @@ -834,11 +822,26 @@ def guided_init_wizard(ctx: typer.Context, guided_init: str): auto_enter=False, ).unsafe_ask() - if not disable_checks and inputs.repository_auto_provision: - check_repository_creds(ctx, git_provider) + if inputs.repository_auto_provision: + org_name = questionary.text( + f"Which user or organization will this repository live under? ({repo_url.format(git_provider=git_provider, org_name='', repo_name='')})", + qmark=qmark, + ).unsafe_ask() + + repo_name = questionary.text( + f"And what will the name of this repository be? ({repo_url.format(git_provider=git_provider, org_name=org_name, repo_name='')})", + qmark=qmark, + ).unsafe_ask() + + inputs.repository = repo_url.format( + git_provider=git_provider, + org_name=org_name, + repo_name=repo_name, + ) + + if not disable_checks: + check_repository_creds(ctx, git_provider) - if git_provider == GitRepoEnum.github.value.lower(): - inputs.ci_provider = CiEnum.github_actions.value.lower() elif git_provider == GitRepoEnum.gitlab.value.lower(): inputs.ci_provider = CiEnum.gitlab_ci.value.lower() diff --git a/src/nebari/schema.py b/src/nebari/schema.py index e138b4c24..6a809842d 100644 --- a/src/nebari/schema.py +++ b/src/nebari/schema.py @@ -19,7 +19,7 @@ email_regex = "^[^ @]+@[^ @]+\\.[^ @]+$" email_pydantic = Annotated[str, StringConstraints(pattern=email_regex)] -github_url_regex = "^(https://)?github.com/([^/]+)/([^/]+)/?$" +github_url_regex = r"^(https://)?github\.com/([^/]+)/([^/]+)/?$" github_url_pydantic = Annotated[str, StringConstraints(pattern=github_url_regex)] diff --git a/tests/tests_unit/conftest.py b/tests/tests_unit/conftest.py index d78dfdf1e..ce60e4479 100644 --- a/tests/tests_unit/conftest.py +++ b/tests/tests_unit/conftest.py @@ -125,7 +125,7 @@ def _mock_return_value(return_value): "gcp.nebari.dev", schema.ProviderEnum.gcp, GCP_DEFAULT_REGION, - CiEnum.github_actions, + CiEnum.gitlab_ci, AuthenticationEnum.password, ), ( @@ -154,6 +154,11 @@ def nebari_config_options(request) -> schema.Main: auth_provider, ) = request.param + if ci_provider == CiEnum.github_actions: + repo = DEFAULT_GH_REPO + else: + repo = None + return dict( project_name=project, namespace=namespace, @@ -162,7 +167,7 @@ def nebari_config_options(request) -> schema.Main: region=region, ci_provider=ci_provider, auth_provider=auth_provider, - repository=DEFAULT_GH_REPO, + repository=repo, repository_auto_provision=False, auth_auto_provision=False, terraform_state=DEFAULT_TERRAFORM_STATE, diff --git a/tests/tests_unit/test_cli_init_repository.py b/tests/tests_unit/test_cli_init_repository.py index 6bc0d4e7d..34746722b 100644 --- a/tests/tests_unit/test_cli_init_repository.py +++ b/tests/tests_unit/test_cli_init_repository.py @@ -174,21 +174,19 @@ def test_cli_init_error_repository_missing_env(monkeypatch: pytest.MonkeyPatch): assert tmp_file.exists() is False -def test_cli_init_error_invalid_repo(monkeypatch: pytest.MonkeyPatch): - monkeypatch.setenv("GITHUB_USERNAME", TEST_GITHUB_USERNAME) - monkeypatch.setenv("GITHUB_TOKEN", TEST_GITHUB_TOKEN) - +@pytest.mark.parametrize( + "url", + [ + "https://github.com", + "http://github.com/user/repo", + "https://github.com/user/" "github.com/user/repo", + "https://notgithub.com/user/repository", + ], +) +def test_cli_init_error_invalid_repo(url): app = create_cli() - args = [ - "init", - "local", - "--project-name", - "test", - "--repository-auto-provision", - "--repository", - "https://notgithub.com", - ] + args = ["init", "local", "--project-name", "test", "--repository", url] with tempfile.TemporaryDirectory() as tmp: tmp_file = Path(tmp).resolve() / "nebari-config.yaml"