66from enum import Enum
77from itertools import cycle
88from pathlib import Path
9- from typing import Any , Dict , List , Optional , Tuple , Union
9+ from typing import Any , Dict , List , Optional , Union
1010
1111import rignore
1212import typer
@@ -163,6 +163,16 @@ def _get_apps(team_slug: str) -> List[AppResponse]:
163163 return [AppResponse .model_validate (app ) for app in data ]
164164
165165
166+ def _get_team (team_id : str ) -> Team :
167+ with APIClient () as client :
168+ response = client .get (f"/teams/{ team_id } " )
169+ response .raise_for_status ()
170+
171+ data = response .json ()
172+
173+ return Team .model_validate (data )
174+
175+
166176class DeploymentResponse (BaseModel ):
167177 id : str
168178 app_id : str
@@ -202,9 +212,7 @@ def _get_deployment(app_id: str, deployment_id: str) -> DeploymentResponse:
202212]
203213
204214
205- def _configure_app (
206- toolkit : RichToolkit , path_to_deploy : Path
207- ) -> Tuple [AppConfig , AppResponse ]:
215+ def _configure_app (toolkit : RichToolkit , path_to_deploy : Path ) -> AppConfig :
208216 if not toolkit .confirm (f"Setup and deploy [blue]{ path_to_deploy } [/]?" , tag = "dir" ):
209217 raise typer .Exit (0 )
210218
@@ -271,7 +279,7 @@ def _configure_app(
271279
272280 write_app_config (path_to_deploy , app_config )
273281
274- return app_config , app
282+ return app_config
275283
276284
277285def _wait_for_deployment (
@@ -348,33 +356,31 @@ def deploy(
348356 path_to_deploy = path or Path .cwd ()
349357
350358 app_config = get_app_config (path_to_deploy )
351- app_data : Optional [AppResponse ] = None
352359
353360 if not app_config :
354- app_config , app_data = _configure_app (
355- toolkit , path_to_deploy = path_to_deploy
356- )
361+ app_config = _configure_app (toolkit , path_to_deploy = path_to_deploy )
357362 else :
358363 toolkit .print ("Deploying app..." )
359364 toolkit .print_line ()
360365
361- with toolkit .progress ("Checking app..." , transient = True ) as progress :
362- app_data = _get_app (app_config .app_id )
366+ with toolkit .progress ("Checking app..." , transient = True ) as progress :
367+ app = _get_app (app_config .app_id )
368+ team = _get_team (app_config .team_id )
363369
364- if not app_data :
365- progress .set_error (
366- "App not found. Make sure you're logged in the correct account."
367- )
370+ if not app :
371+ progress .set_error (
372+ "App not found. Make sure you're logged in the correct account."
373+ )
368374
369- raise typer .Exit (1 )
375+ raise typer .Exit (1 )
370376
371377 toolkit .print_line ()
372378
373379 archive_path = archive (path or Path .cwd ()) # noqa: F841
374380
375381 with toolkit .progress (title = "Creating deployment" ) as progress :
376382 with handle_http_errors (progress ):
377- deployment = _create_deployment (app_data .id )
383+ deployment = _create_deployment (app .id )
378384
379385 progress .log (
380386 f"Deployment created successfully! Deployment slug: { deployment .slug } "
@@ -390,13 +396,11 @@ def deploy(
390396
391397 check_deployment_url = (
392398 settings .base_frontend_url
393- + f"/apps/{ app_data .slug } /deployments/{ deployment .id } "
399+ + f"/{ team . slug } / apps/{ app .slug } /deployments/{ deployment .id } "
394400 )
395401
396402 if not skip_wait :
397- _wait_for_deployment (
398- toolkit , app_data .id , deployment .id , check_deployment_url
399- )
403+ _wait_for_deployment (toolkit , app .id , deployment .id , check_deployment_url )
400404 else :
401405 toolkit .print (
402406 f"Check the status of your deployment at [link]{ check_deployment_url } [/link]"
0 commit comments