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 6 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
6 changes: 3 additions & 3 deletions src/_nebari/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from _nebari.stages.terraform_state import TerraformStateEnum
from _nebari.utils import get_latest_kubernetes_version, random_secure_string
from _nebari.version import __version__
from nebari.schema import ProviderEnum, github_url_regex
from nebari.schema import ProviderEnum, git_url_regex

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -194,10 +194,10 @@ def render_config(
print(str(e))

if repository_auto_provision:
match = re.search(github_url_regex, repository)
match = re.search(git_url_regex, repository)
if match:
git_repository = github_auto_provision(
config_model, match.group(2), match.group(3)
config_model, match.group(5), match.group(6)
)
git_repository_initialize(git_repository)
else:
Expand Down
4 changes: 2 additions & 2 deletions src/_nebari/subcommands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class InitInputs(schema.Base):
namespace: Optional[schema.namespace_pydantic] = "dev"
auth_provider: AuthenticationEnum = AuthenticationEnum.password
auth_auto_provision: bool = False
repository: Optional[schema.github_url_pydantic] = None
repository: Optional[schema.git_url_pydantic] = None
repository_auto_provision: bool = False
ci_provider: CiEnum = CiEnum.none
terraform_state: TerraformStateEnum = TerraformStateEnum.remote
Expand Down Expand Up @@ -519,7 +519,7 @@ def init(
None,
help="Github repository URL to be initialized with --repository-auto-provision",
callback=typer_validate_regex(
schema.github_url_regex,
schema.git_url_regex,
"Must be a fully qualified GitHub repository URL.",
),
),
Expand Down
4 changes: 2 additions & 2 deletions src/nebari/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
email_regex = "^[^ @]+@[^ @]+\\.[^ @]+$"
email_pydantic = pydantic.constr(regex=email_regex)

github_url_regex = "^(https://)?github.com/([^/]+)/([^/]+)/?$"
github_url_pydantic = pydantic.constr(regex=github_url_regex)
git_url_regex = "^(https://)?(git)(hub|lab)(.com)/([^/]+)/([^/]+)/*$"
marcelovilla marked this conversation as resolved.
Show resolved Hide resolved
git_url_pydantic = pydantic.constr(regex=git_url_regex)


class Base(pydantic.BaseModel):
Expand Down
48 changes: 36 additions & 12 deletions tests/tests_unit/test_cli_init_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,21 +174,45 @@ 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/user/repository",
"https://gitlab.com/user/repository/",
],
)
def test_cli_init_valid_repo(url):
app = create_cli()

args = ["init", "local", "--project-name", "test", "--repository", url]

with tempfile.TemporaryDirectory() as tmp:
tmp_file = Path(tmp).resolve() / "nebari-config.yaml"
assert tmp_file.exists() is False

result = runner.invoke(app, args + ["--output", tmp_file.resolve()])

assert 0 == result.exit_code
assert not result.exception
assert tmp_file.exists() is True
marcelovilla marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.parametrize(
"url",
[
"https://github.com",
"https://gitlab.com/user/",
"https://gitlab.com/user",
"http://github.com/user/",
"gitlab.com/user/",
"github.com",
"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