All checks were successful
Build and Deploy Log Center / build-and-deploy (push) Successful in 2m16s
- 新增 Project 模型(repo_url, local_path, name, description) - 项目 CRUD API(GET/PUT /api/v1/projects) - 日志上报自动 upsert Project 记录 - ErrorLog 增加 failure_reason 字段 - update_task_status / create_repair_report 写入失败原因 - Repair Agent 优先从 API 获取项目配置,回退 .env - 新增 Web 端「项目管理」页面(表格 + 行内编辑) - BugList/BugDetail/RepairList 展示失败原因 - 更新接入指南文档 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
129 lines
3.9 KiB
Python
129 lines
3.9 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 LogSource(str, Enum):
|
|
RUNTIME = "runtime"
|
|
CICD = "cicd"
|
|
DEPLOYMENT = "deployment"
|
|
|
|
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 Project(SQLModel, table=True):
|
|
"""项目信息"""
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
project_id: str = Field(unique=True, index=True)
|
|
name: Optional[str] = Field(default=None)
|
|
repo_url: Optional[str] = Field(default=None)
|
|
local_path: Optional[str] = Field(default=None)
|
|
description: Optional[str] = Field(default=None)
|
|
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
|
|
|
class ProjectUpdate(SQLModel):
|
|
"""项目编辑 schema"""
|
|
name: Optional[str] = None
|
|
repo_url: Optional[str] = None
|
|
local_path: Optional[str] = None
|
|
description: Optional[str] = None
|
|
|
|
class ErrorLog(SQLModel, table=True):
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
project_id: str = Field(index=True)
|
|
environment: str
|
|
level: str
|
|
|
|
# Source
|
|
source: str = Field(default="runtime", index=True)
|
|
|
|
# Error Details
|
|
error_type: str
|
|
error_message: str
|
|
file_path: Optional[str] = None
|
|
line_number: Optional[int] = None
|
|
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)
|
|
|
|
# Repair Tracking
|
|
failure_reason: Optional[str] = Field(default=None, sa_column=Column(Text, nullable=True))
|
|
|
|
# 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
|
|
repo_url: Optional[str] = None
|
|
|
|
source: str = "runtime"
|
|
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
|
|
|
|
# Repair Round Tracking
|
|
repair_round: int = Field(default=1) # Which round (1, 2, 3...)
|
|
failure_reason: Optional[str] = Field(default=None, sa_column=Column(Text, nullable=True))
|
|
|
|
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
|
|
repair_round: int = 1
|
|
failure_reason: Optional[str] = None
|
|
|