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

feat: Cloud CLI for adding projects #7620

Merged
merged 58 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c5c7476
wip
Apr 27, 2023
f4414e3
first pass
Apr 27, 2023
7028745
Merge branch 'cloud' into kgpayne/issue7412
Apr 27, 2023
3aaf5e8
await response
Apr 27, 2023
c510bbe
Merge branch 'cloud' into kgpayne/issue7412
May 3, 2023
c473da8
tests and pr feedback
May 3, 2023
4e89668
tidy up
May 4, 2023
3a391f3
Merge branch 'cloud' into kgpayne/issue7412
May 4, 2023
3693eab
Update src/cloud-cli/meltano/cloud/cli/project.py
May 4, 2023
938f616
Update src/cloud-cli/tests/cli/test_project.py
May 4, 2023
26bfa27
Merge branch 'cloud' into kgpayne/issue7412
May 5, 2023
ca3341b
poetry update
May 5, 2023
f2edfc9
Merge branch 'cloud' into kgpayne/issue7412
May 15, 2023
cf67cfd
Merge branch 'cloud' into kgpayne/issue7412
cjohnhanson Jul 17, 2023
e35b699
Project add command
cjohnhanson Jul 18, 2023
49f4639
Use new provisioner API projects endpoint in project add command
cjohnhanson Jul 19, 2023
a2fa7da
Use yaspin
cjohnhanson Jul 19, 2023
770919e
[pre-commit.ci] auto fixes from pre-commit.ci hooks
pre-commit-ci[bot] Jul 19, 2023
30c655f
Add -> create
cjohnhanson Jul 19, 2023
861dcbb
Merge branch 'cloud' into kgpayne/issue7412
cjohnhanson Jul 19, 2023
eb616a4
Merge branch 'kgpayne/issue7412' into INFRA-988-deploy-project-stack-…
cjohnhanson Jul 19, 2023
dcf6816
Add -> create in tests
cjohnhanson Jul 20, 2023
3340adc
[pre-commit.ci] auto fixes from pre-commit.ci hooks
pre-commit-ci[bot] Jul 20, 2023
93e74cb
Merge branch 'cloud' into kgpayne/issue7412
cjohnhanson Jul 28, 2023
9280990
Merge branch 'kgpayne/issue7412' into INFRA-988-deploy-project-stack-…
cjohnhanson Jul 28, 2023
8d68cbe
feat: Deploy project stack on creation (#7925)
cjohnhanson Jul 28, 2023
6fab957
merge cloud
cjohnhanson Aug 3, 2023
7431f5e
Merge branch 'cloud' into INFRA-988-deploy-project-stack-on-creation
cjohnhanson Aug 7, 2023
e073299
Update src/cloud-cli/meltano/cloud/cli/project.py
cjohnhanson Aug 7, 2023
ab367b3
Update src/cloud-cli/meltano/cloud/cli/project.py
cjohnhanson Aug 7, 2023
f443689
Update src/cloud-cli/meltano/cloud/cli/project.py
cjohnhanson Aug 7, 2023
5be269f
Update src/cloud-cli/meltano/cloud/cli/project.py
cjohnhanson Aug 7, 2023
6745784
Update src/cloud-cli/tests/cli/test_project.py
cjohnhanson Aug 7, 2023
bbce161
Update src/cloud-cli/tests/cli/test_project.py
cjohnhanson Aug 7, 2023
b00c218
merging cloud
cjohnhanson Aug 7, 2023
a4b8503
Don't print created project json
cjohnhanson Aug 7, 2023
8db1246
project_name -> name
cjohnhanson Aug 7, 2023
4b9e567
repository-url -> git-repository
cjohnhanson Aug 7, 2023
7b6d3d2
correct project create args in test
cjohnhanson Aug 7, 2023
297bec9
correct project create args in test
cjohnhanson Aug 7, 2023
03dbb64
project-root-path -> root-path
cjohnhanson Aug 8, 2023
2ec325d
[pre-commit.ci] auto fixes from pre-commit.ci hooks
pre-commit-ci[bot] Aug 8, 2023
11b9119
Merge branch 'cloud' into kgpayne/issue7412
cjohnhanson Aug 11, 2023
daaa92a
Update project create test
cjohnhanson Aug 11, 2023
ec7bfe6
Update src/meltano/cloud/cli/project.py
cjohnhanson Aug 11, 2023
cbdb557
Update src/meltano/cloud/cli/project.py
cjohnhanson Aug 11, 2023
537e2e5
Update src/meltano/cloud/cli/project.py
cjohnhanson Aug 11, 2023
e4a7d56
PR feedback
cjohnhanson Aug 11, 2023
f13e507
Add project create to cloud-cli docs.
cjohnhanson Aug 11, 2023
f511f1d
More flexible expected stdout output for project create test
cjohnhanson Aug 11, 2023
f199c9b
ignore type checks for yaspin
cjohnhanson Aug 11, 2023
9f7554b
Merge branch 'cloud' into kgpayne/issue7412
cjohnhanson Aug 21, 2023
4e8ae89
re-add signed request
cjohnhanson Aug 21, 2023
96444ec
[pre-commit.ci] auto fixes from pre-commit.ci hooks
pre-commit-ci[bot] Aug 21, 2023
2172f13
Merge branch 'cloud' into kgpayne/issue7412
cjohnhanson Aug 21, 2023
b9e79f5
[pre-commit.ci] auto fixes from pre-commit.ci hooks
pre-commit-ci[bot] Aug 21, 2023
da30a4f
Addressing pr feedback for docs.
cjohnhanson Aug 22, 2023
421362b
Merge branch 'cloud' into kgpayne/issue7412
cjohnhanson Aug 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/cloud-cli/meltano/cloud/cli/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@
),
)

async def add_project(
self,
project_name: str,
git_repository: str,
project_root_path: str | None = None,
):
"""Use POST to add new Meltano Cloud project."""
async with self.authenticated():
payload = {"project_name": project_name, "git_repository": git_repository}
if project_root_path:
payload["project_root_path"] = project_root_path

return await self._json_request(
"POST",
f"/projects/v1/{self.config.tenant_resource_key}",
json=payload,
)


@click.group("project")
def project_group() -> None:
Expand Down Expand Up @@ -86,7 +104,7 @@
results.extend(response["results"])

if response["pagination"] and len(results) < limit:
page_token = response["pagination"]["next_page_token"]

Check warning on line 107 in src/cloud-cli/meltano/cloud/cli/project.py

View check run for this annotation

Codecov / codecov/patch

src/cloud-cli/meltano/cloud/cli/project.py#L107

Added line #L107 was not covered by tests
else:
break

Expand Down Expand Up @@ -213,7 +231,7 @@
return None

if platform.system() == "Windows":
asyncio.set_event_loop_policy(

Check warning on line 234 in src/cloud-cli/meltano/cloud/cli/project.py

View check run for this annotation

Codecov / codecov/patch

src/cloud-cli/meltano/cloud/cli/project.py#L234

Added line #L234 was not covered by tests
asyncio.WindowsSelectorEventLoopPolicy(), # type: ignore[attr-defined]
)

Expand Down Expand Up @@ -282,7 +300,7 @@
context.projects = await _get_projects(context.config)
_check_for_duplicate_project_names(context.projects)
if project_name not in {x["project_name"] for x in context.projects}:
raise click.ClickException(

Check warning on line 303 in src/cloud-cli/meltano/cloud/cli/project.py

View check run for this annotation

Codecov / codecov/patch

src/cloud-cli/meltano/cloud/cli/project.py#L303

Added line #L303 was not covered by tests
f"Unable to use project named {project_name!r} - no available "
"project matches name.",
)
Expand All @@ -296,3 +314,26 @@
),
fg="green",
)


@project_group.command("add")
@click.option("--project_name", type=str, required=True)
@click.option("--git_repository", type=str, required=True)
@click.option("--project_root_path", type=str, required=False)
kgpayne marked this conversation as resolved.
Show resolved Hide resolved
@pass_context
@run_async
async def add_project(
context: MeltanoCloudCLIContext,
project_name: str,
git_repository: str,
project_root_path: str | None = None,
):
"""Add a project to your Meltano Cloud."""
async with ProjectsCloudClient(config=context.config) as client:
response = await client.add_project(
project_name=project_name,
git_repository=git_repository,
project_root_path=project_root_path,
)
click.echo(f"Project {project_name} created successfully.")
cjohnhanson marked this conversation as resolved.
Show resolved Hide resolved
click.echo(json.dumps(response))
33 changes: 33 additions & 0 deletions src/cloud-cli/tests/cli/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,36 @@ def test_project_use_by_name_and_id_error(self, config: MeltanoCloudConfig):
)
assert result.exit_code == 2
assert "The '--name' and '--id' options are mutually exclusive" in result.output

def test_project_add(
self,
projects: list[CloudProject],
httpserver: HTTPServer,
config: MeltanoCloudConfig,
):
for project in projects[:3]:
httpserver.expect_oneshot_request(
f"/projects/v1/{project['tenant_resource_key']}",
method="POST",
).respond_with_json(project)
result = CliRunner().invoke(
cli,
(
"--config-path",
config.config_path,
"project",
"add",
"--project_name",
project["project_name"],
"--git_repository",
project["git_repository"],
"--project_root_path",
project["project_root_path"],
kgpayne marked this conversation as resolved.
Show resolved Hide resolved
),
)
assert result.exit_code == 0, result.output
assert result.output == (
f"Project {project['project_name']} created successfully.\n"
cjohnhanson marked this conversation as resolved.
Show resolved Hide resolved
+ json.dumps(project)
+ "\n"
)