Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor GitOps approach prompt flow in guided init #2269

Merged
merged 14 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 21 additions & 18 deletions src/_nebari/subcommands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,33 +812,36 @@ 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='<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='<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,
qmark=qmark,
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='<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='<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()

Expand Down
2 changes: 1 addition & 1 deletion src/nebari/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]


Expand Down
9 changes: 7 additions & 2 deletions tests/tests_unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
(
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
24 changes: 11 additions & 13 deletions tests/tests_unit/test_cli_init_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading