bridge.py
python
sha256:cdfe164af70b640f93370907508ae9066c78c19dfd97f36e14aab34c3d539496
docs: add production-readiness checklist
Sonnet 5
33 days ago
| 1 | """Pydantic models for the muse bridge mirror registry API (Phase 7).""" |
| 2 | |
| 3 | from datetime import datetime |
| 4 | |
| 5 | from pydantic import Field, field_validator |
| 6 | |
| 7 | from musehub.models.base import CamelModel |
| 8 | |
| 9 | _VALID_DIRECTIONS = {"export", "import", "bidirectional"} |
| 10 | |
| 11 | class CreateMirrorRequest(CamelModel): |
| 12 | """Request body for POST /repos/{repo_id}/mirrors.""" |
| 13 | |
| 14 | git_remote_url: str = Field(..., min_length=1, description="URL of the remote Git repository") |
| 15 | git_branch: str = Field("muse-mirror", min_length=1, description="Branch name on the Git remote") |
| 16 | direction: str = Field(..., description="Sync direction: 'export', 'import', or 'bidirectional'") |
| 17 | auto_export: bool = Field(False, description="Automatically export on every Muse push") |
| 18 | |
| 19 | @field_validator("direction") |
| 20 | @classmethod |
| 21 | def _validate_direction(cls, v: str) -> str: |
| 22 | if v not in _VALID_DIRECTIONS: |
| 23 | raise ValueError( |
| 24 | f"direction must be one of {sorted(_VALID_DIRECTIONS)}, got {v!r}" |
| 25 | ) |
| 26 | return v |
| 27 | |
| 28 | @field_validator("git_remote_url") |
| 29 | @classmethod |
| 30 | def _validate_url(cls, v: str) -> str: |
| 31 | if not v.strip(): |
| 32 | raise ValueError("git_remote_url must not be empty or whitespace") |
| 33 | return v.strip() |
| 34 | |
| 35 | class MirrorResponse(CamelModel): |
| 36 | """Wire model for a single bridge mirror entry.""" |
| 37 | |
| 38 | id: str |
| 39 | repo_id: str |
| 40 | git_remote_url: str |
| 41 | git_branch: str |
| 42 | direction: str |
| 43 | last_export_muse_commit_id: str | None |
| 44 | last_export_git_sha: str | None |
| 45 | last_export_at: datetime | None |
| 46 | last_import_git_sha: str | None |
| 47 | last_import_muse_commit_id: str | None |
| 48 | last_import_at: datetime | None |
| 49 | auto_export: bool |
| 50 | created_by: str |
| 51 | created_at: datetime |
| 52 | |
| 53 | class MirrorListResponse(CamelModel): |
| 54 | """Wire model for GET /repos/{repo_id}/mirrors.""" |
| 55 | |
| 56 | mirrors: list[MirrorResponse] |
| 57 | total: int |
File History
1 commit
sha256:cdfe164af70b640f93370907508ae9066c78c19dfd97f36e14aab34c3d539496
docs: add production-readiness checklist
Sonnet 5
33 days ago