99 lines
2.1 KiB
Python
99 lines
2.1 KiB
Python
"""Data models for integration service."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from .shared import Any, BaseModel, Dict, Enum, Field, List, Optional, datetime
|
|
|
|
|
|
class IntegrationType(str, Enum):
|
|
"""Integration type."""
|
|
|
|
PLANE = "plane"
|
|
LARK = "lark"
|
|
GITHUB = "github"
|
|
GITLAB = "gitlab"
|
|
|
|
|
|
class IntegrationStatus(str, Enum):
|
|
"""Integration runtime status."""
|
|
|
|
ACTIVE = "active"
|
|
INACTIVE = "inactive"
|
|
ERROR = "error"
|
|
DEGRADED = "degraded"
|
|
PENDING = "pending"
|
|
|
|
|
|
class PlaneConfig(BaseModel):
|
|
"""Plane integration config."""
|
|
|
|
api_url: str = "https://api.plane.so/api/v1"
|
|
api_key: str = ""
|
|
workspace_slug: str = ""
|
|
project_id: str = ""
|
|
enabled: bool = True
|
|
|
|
|
|
class LarkConfig(BaseModel):
|
|
"""Lark integration config."""
|
|
|
|
app_id: str = ""
|
|
app_secret: str = ""
|
|
verification_token: str = ""
|
|
encrypt_key: str = ""
|
|
default_chat_id: str = ""
|
|
enabled: bool = True
|
|
|
|
|
|
class IntegrationHealth(BaseModel):
|
|
"""Integration health record."""
|
|
|
|
type: IntegrationType
|
|
status: IntegrationStatus
|
|
last_check: datetime
|
|
last_success: Optional[datetime] = None
|
|
last_error: Optional[str] = None
|
|
error_count: int = 0
|
|
consecutive_failures: int = 0
|
|
latency_ms: Optional[float] = None
|
|
message: str = ""
|
|
|
|
|
|
class IntegrationConfig(BaseModel):
|
|
"""Composite integration config."""
|
|
|
|
plane: PlaneConfig = Field(default_factory=PlaneConfig)
|
|
lark: LarkConfig = Field(default_factory=LarkConfig)
|
|
|
|
|
|
class TaskSyncResult(BaseModel):
|
|
"""Task synchronization result."""
|
|
|
|
success: bool
|
|
integration_type: IntegrationType
|
|
tasks_created: int = 0
|
|
tasks_updated: int = 0
|
|
errors: List[str] = Field(default_factory=list)
|
|
details: Dict[str, Any] = Field(default_factory=dict)
|
|
|
|
|
|
class NotificationResult(BaseModel):
|
|
"""Notification send result."""
|
|
|
|
success: bool
|
|
integration_type: IntegrationType
|
|
recipients: int = 0
|
|
error: Optional[str] = None
|
|
|
|
|
|
__all__ = [
|
|
"IntegrationType",
|
|
"IntegrationStatus",
|
|
"PlaneConfig",
|
|
"LarkConfig",
|
|
"IntegrationHealth",
|
|
"IntegrationConfig",
|
|
"TaskSyncResult",
|
|
"NotificationResult",
|
|
]
|