MCPcopy Index your code
hub / github.com/hunvreus/devpush / update_environment

Method update_environment

app/models.py:449–493  ·  view source on GitHub ↗

Update environment

(self, environment_id: str, values: dict)

Source from the content-addressed store, hash-verified

447 return env
448
449 def update_environment(self, environment_id: str, values: dict) -> dict | None:
450 """Update environment"""
451 env = self.get_environment_by_id(environment_id)
452 if not env:
453 return None
454
455 # Prevent production rename
456 if environment_id == "prod" and (
457 env.get("name") != values.get("name")
458 or env.get("slug") != values.get("slug")
459 ):
460 raise ValueError("Cannot modify production environment")
461
462 # If changing slug, check it's unique
463 new_slug = values.get("slug")
464 if (
465 new_slug
466 and new_slug != env.get("slug")
467 and self.has_active_environment_with_slug(
468 new_slug, exclude_id=environment_id
469 )
470 ):
471 raise ValueError(
472 f"An active environment with slug '{new_slug}' already exists"
473 )
474
475 # Update the environment
476 env_index = next(
477 i for i, e in enumerate(self.environments) if e["id"] == environment_id
478 )
479 old_slug = self.environments[env_index]["slug"]
480
481 environments = self.environments.copy()
482 environments[env_index] = {**environments[env_index], **values}
483 self.environments = environments
484
485 # Update env vars if slug changed
486 if new_slug and new_slug != old_slug:
487 env_vars = self.env_vars.copy()
488 for var in env_vars:
489 if var.get("environment") == old_slug:
490 var["environment"] = new_slug
491 self.env_vars = env_vars
492
493 return environments[env_index]
494
495 def delete_environment(self, environment_id: str | None) -> bool:
496 """Soft delete environment"""

Callers 1

project_settingsFunction · 0.80

Calls 3

get_environment_by_idMethod · 0.95
nextFunction · 0.85

Tested by

no test coverage detected