All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 1m35s
95 lines
2.8 KiB
Python
95 lines
2.8 KiB
Python
from datetime import datetime
|
|
from typing import Optional, Dict, List
|
|
from sqlmodel import SQLModel, Field, Column, JSON, Text
|
|
from enum import Enum
|
|
|
|
class LogStatus(str, Enum):
|
|
NEW = "NEW"
|
|
VERIFYING = "VERIFYING"
|
|
CANNOT_REPRODUCE = "CANNOT_REPRODUCE"
|
|
PENDING_FIX = "PENDING_FIX"
|
|
FIXING = "FIXING"
|
|
FIXED = "FIXED"
|
|
VERIFIED = "VERIFIED"
|
|
DEPLOYED = "DEPLOYED"
|
|
FIX_FAILED = "FIX_FAILED"
|
|
|
|
class ErrorLog(SQLModel, table=True):
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
project_id: str = Field(index=True)
|
|
environment: str
|
|
level: str
|
|
|
|
# Error Details
|
|
error_type: str
|
|
error_message: str
|
|
file_path: str
|
|
line_number: int
|
|
stack_trace: str = Field(sa_column=Column(JSON)) # Store full stack trace
|
|
|
|
# Context
|
|
context: Dict = Field(default={}, sa_column=Column(JSON))
|
|
|
|
# Versioning
|
|
version: Optional[str] = None
|
|
commit_hash: Optional[str] = None
|
|
|
|
# Meta
|
|
timestamp: datetime = Field(default_factory=datetime.utcnow)
|
|
fingerprint: str = Field(unique=True, index=True) # project_id + error_type + file_path + line_number
|
|
|
|
# Status Tracking
|
|
status: LogStatus = Field(default=LogStatus.NEW)
|
|
retry_count: int = Field(default=0)
|
|
|
|
# Relationships could be added here (e.g., to a RepairTask table if 1:N)
|
|
# For simplicity, we track status on the Log itself for now.
|
|
|
|
# Pydantic Models for API
|
|
class ErrorLogCreate(SQLModel):
|
|
project_id: str
|
|
environment: str
|
|
level: str
|
|
timestamp: Optional[datetime] = None
|
|
version: Optional[str] = None
|
|
commit_hash: Optional[str] = None
|
|
|
|
error: Dict # {type, message, file_path, line_number, stack_trace}
|
|
context: Optional[Dict] = {}
|
|
|
|
class TaskStatusUpdate(SQLModel):
|
|
status: LogStatus
|
|
message: Optional[str] = None
|
|
|
|
class RepairTask(SQLModel, table=True):
|
|
"""Record of a repair attempt"""
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
error_log_id: int = Field(foreign_key="errorlog.id")
|
|
status: LogStatus
|
|
project_id: str
|
|
|
|
# Repair Details
|
|
ai_analysis: str = Field(sa_column=Column(Text)) # Analysis from LLM
|
|
fix_plan: str = Field(sa_column=Column(Text)) # Proposed fix plan
|
|
code_diff: str = Field(sa_column=Column(Text)) # Git diff
|
|
modified_files: List[str] = Field(sa_column=Column(JSON))
|
|
|
|
# Test Results
|
|
test_output: str = Field(sa_column=Column(Text))
|
|
test_passed: bool
|
|
|
|
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
|
|
class RepairTaskCreate(SQLModel):
|
|
"""Schema for creating a repair report via API"""
|
|
error_log_id: int
|
|
status: LogStatus
|
|
project_id: str
|
|
ai_analysis: str
|
|
fix_plan: str
|
|
code_diff: str
|
|
modified_files: List[str]
|
|
test_output: str
|
|
test_passed: bool
|
|
|