refactor: 移除 SMTP 相关代码,简化用户创建流程,更新文档

This commit is contained in:
2026-04-13 12:27:14 +08:00
parent 919c561629
commit 66c254e0ff
13 changed files with 41 additions and 466 deletions
+25 -25
View File
@@ -33,13 +33,6 @@ cp .secrets.toml.example .secrets.toml
```toml
[default.gitea]
token = "your-gitea-api-token" # 必填
[default.smtp]
host = "smtp.example.com" # 发送邮件时必填
port = 465
user = "[email protected]"
password = "your-smtp-password"
from_addr = "同济大学高级语言程序设计课程 <[email protected]>"
```
API Token 获取方式: 登录 Gitea -> 设置 -> 应用 -> 生成令牌(勾选所有权限)。
@@ -87,10 +80,30 @@ tjhlp
├── stats
│ ├── summary Issue 统计摘要
│ └── export 导出 Issue 数据到 CSV
└── notify
└── send-credentials 通过 SMTP 发送账号密码邮件
└── labels
├── sync 同步预定义 Label 到仓库
└── list 列出仓库 Label
```
## 典型工作流
### 学期初始化
```bash
# 1. 检查连接
uv run tjhlp setup status
# 2. 一键初始化(创建组织 + 团队 + general 仓库 + Labels + Webhook)
uv run tjhlp setup init \
--org tjhlp-2025f \
--webhook-url http://notify-server:8080/webhook \
--webhook-secret mysecret
# 3. 批量创建用户并分配到团队
uv run tjhlp users create --file members.csv --org tjhlp-2025f
```
## 典型工作流
### 学期初始化
@@ -164,20 +177,10 @@ id,name,role
- `name` - 姓名, 作为 Gitea 的 full_name
- `role` - `student` 或 `ta`, 决定分配到哪个团队
- 邮箱自动生成为 `{id}@tongji.edu.cn`
- **初始密码与用户名(学号/工号)相同**。
示例文件见 `example/members.csv`。
### 输出: `credentials_*.csv`
`users create` 执行后自动生成:
```csv
id,name,role,username,password,email
2659999,赵一伤,student,2659999,xK9#mP2$vL4w,[email protected]
```
此文件包含随机生成的初始密码, 用于 `notify send-credentials` 发送邮件。**请妥善保管并在使用后删除。**
## 预定义 Label
通过 `settings.toml` 配置, `setup init` 和 `labels sync` 时自动创建:
@@ -230,9 +233,8 @@ uv run ruff format --check src/
tests/
├── conftest.py 公共 fixtures(mock config、client、样本数据)
├── test_models.py 数据模型(MemberRecord、Gitea API 模型、枚举)
├── test_config.py 配置校验(LabelDef 颜色、GiteaConfig/SmtpConfig 必填字段)
├── test_config.py 配置校验(LabelDef 颜色、GiteaConfig 必填字段)
├── test_utils.py 工具函数(parse_repo、compute_issue_stats)
├── test_pure_functions.py 纯函数(密码生成、CSV 解析、邮件模板)
├── test_client.py API 客户端(respx mock HTTP, 分页、错误处理、CRUD)
└── test_commands.py 命令集成(CliRunner + mock, setup/users/repos 流程)
```
@@ -254,7 +256,6 @@ tests/
| `config.py` | 87% | Pydantic 校验逻辑(未覆盖 Dynaconf 加载函数) |
| `users.py` | 79% | 创建/跳过/删除流程 |
| `client.py` | 67% | 核心 HTTP 方法和分页(未覆盖所有 API endpoint) |
| `notify.py` | 38% | 邮件文本构建(未覆盖 SMTP 发送) |
## 项目结构
@@ -286,8 +287,7 @@ scripts/
├── repos.py 仓库管理
├── webhooks.py Webhook 管理
├── labels.py Label 管理
├── stats.py Issue 统计
└── notify.py 邮件通知
└── stats.py Issue 统计
```
## 技术选型