SHA256
97 lines
2.0 KiB
Python
97 lines
2.0 KiB
Python
"""Pydantic 数据模型: 用于 CSV 解析、API 请求/响应"""
|
|
|
|
from enum import StrEnum
|
|
|
|
from pydantic import BaseModel, computed_field
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 枚举
|
|
# ---------------------------------------------------------------------------
|
|
class MemberRole(StrEnum):
|
|
STUDENT = "student"
|
|
TA = "ta"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# CSV 输入模型
|
|
# ---------------------------------------------------------------------------
|
|
class MemberRecord(BaseModel):
|
|
"""members.csv 中的一行记录"""
|
|
|
|
id: str
|
|
name: str
|
|
role: MemberRole
|
|
|
|
@computed_field
|
|
@property
|
|
def email(self) -> str:
|
|
return f"{self.id}@tongji.edu.cn"
|
|
|
|
@computed_field
|
|
@property
|
|
def username(self) -> str:
|
|
return self.id
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Gitea API 响应模型(部分字段)
|
|
# ---------------------------------------------------------------------------
|
|
class GiteaUser(BaseModel):
|
|
id: int
|
|
login: str
|
|
full_name: str = ""
|
|
email: str = ""
|
|
is_admin: bool = False
|
|
active: bool = True
|
|
|
|
|
|
class GiteaOrg(BaseModel):
|
|
id: int
|
|
name: str
|
|
full_name: str = ""
|
|
description: str = ""
|
|
|
|
|
|
class GiteaTeam(BaseModel):
|
|
id: int
|
|
name: str
|
|
permission: str = ""
|
|
units: list[str] = []
|
|
|
|
|
|
class GiteaRepo(BaseModel):
|
|
id: int
|
|
name: str
|
|
full_name: str = ""
|
|
description: str = ""
|
|
private: bool = False
|
|
html_url: str = ""
|
|
|
|
|
|
class GiteaLabel(BaseModel):
|
|
id: int
|
|
name: str
|
|
color: str
|
|
description: str = ""
|
|
|
|
|
|
class GiteaWebhook(BaseModel):
|
|
id: int
|
|
type: str
|
|
active: bool = True
|
|
config: dict = {}
|
|
events: list[str] = []
|
|
|
|
|
|
class GiteaIssue(BaseModel):
|
|
id: int
|
|
number: int
|
|
title: str
|
|
state: str = ""
|
|
labels: list[GiteaLabel] = []
|
|
comments: int = 0
|
|
created_at: str = ""
|
|
updated_at: str = ""
|
|
user: GiteaUser | None = None
|