admin ff1f9ae07f 限定 weekly-report 工具权限,禁止写操作
通过 allowed-tools 限制为 Read/Glob/Grep + git pull + python,
禁止 Write、Edit 及任意 Bash 命令,临时文件由 Python 脚本自行管理

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 15:14:21 +08:00

120 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: weekly-report
description: 生成项目过去7天的周报通过 Gitea API 统计每位协作者的 commit 和 PR生成个人工作日志与项目整体报告通过 SMTP 发送邮件
argument-hint: ""
allowed-tools: Read, Glob, Grep, Bash(git pull*), Bash(python*)
---
生成当前项目过去 7 天的周报并发送邮件。按以下步骤执行,每步完成后告知用户进度。
## 步骤 1读取配置
读取当前项目根目录的 `report-config.json`
```json
{
"recipients": ["boss@company.com", "team@company.com"],
"project_name": "项目名称",
"smtp_host": "smtphz.qiye.163.com",
"smtp_port": 994
}
```
如果文件不存在,**停止执行**,提示用户在项目根目录创建该文件后重试。
## 步骤 2拉取最新代码
```bash
git pull origin main
```
如果当前目录不是 git 仓库,停止并提示用户。
## 步骤 3从 Gitea API 拉取数据
使用 Glob 工具找到本技能目录下 `fetch_gitea_data.py` 的绝对路径,然后执行:
```bash
python <fetch_gitea_data.py的绝对路径> --days 7 --output /tmp/gitea_data.json
```
脚本会自动从 `git remote get-url origin` 解析 Gitea 实例地址和仓库路径,无需额外配置。
**可选环境变量:**
- `GITEA_TOKEN`:私有仓库访问令牌。公开仓库无需配置;私有仓库若不配置会收到 401 错误。
执行完成后,读取 `/tmp/gitea_data.json` 获取结构化数据,包含:
- `meta`:仓库信息和统计时间范围
- `summary`:总 commit 数、PR 数、贡献者人数
- `by_author`:按作者分组的 commit 和 PR 列表
## 步骤 4生成报告内容
基于 `/tmp/gitea_data.json` 的数据,生成以下内容:
### 个人周报(每位协作者一份,中文)
每人包含:
- 姓名、本周 commit 数、合并 PR 数
- 合并 PR 列表(编号、标题)
- 关键 commit 摘要(按日期列出,去除 merge commit
- 工作总结2-3 句话概括本周主要工作内容和贡献
### 项目整体进度报告(中文)
包含:
- 统计摘要:参与人数、总 commit 数、合并 PR 总数
- 主要完成内容(按功能或模块归类)
- 整体进度评估(根据提交内容客观描述)
- 如有 open PR未合并列出数量作为下周关注点
### 拼装 HTML 邮件
将报告拼装成 HTML写入临时文件
```bash
python -c "from datetime import date; print(f'/tmp/weekly_report_{date.today().strftime(\"%Y%m%d\")}.html')"
```
HTML 结构:
1. 页头:`【周报】<project_name> - <日期范围>`
2. 项目整体报告
3. 分割线
4. 各协作者个人报告(每人一节)
## 步骤 5检查 SMTP 环境变量
```bash
python -c "
import os, sys
required = ['SMTP_HOST', 'SMTP_PORT', 'SMTP_USER', 'SMTP_PASSWORD']
missing = [k for k in required if not os.environ.get(k)]
if missing:
print('缺少:' + ', '.join(missing))
sys.exit(1)
print('检查通过')
"
```
如果有缺失,**停止执行**,提示用户配置以下环境变量(不要硬编码):
| 变量 | 说明 | 示例 |
|------|------|------|
| `SMTP_HOST` | SMTP 服务器地址 | `smtp.qq.com` |
| `SMTP_PORT` | 端口SSL用465STARTTLS用587 | `465` |
| `SMTP_USER` | 发件人邮箱 | `noreply@company.com` |
| `SMTP_PASSWORD` | SMTP 密码或授权码 | `your-auth-code` |
## 步骤 6发送邮件
使用 Glob 找到本技能目录下 `send_email.py` 的绝对路径,然后执行:
```bash
python <send_email.py的绝对路径> \
--config report-config.json \
--subject "【周报】<project_name> <YYYY-MM-DD>" \
--body-file <步骤4生成的HTML文件路径>
```
发送成功后,告知用户已发送至哪些邮箱,并删除 `/tmp/gitea_data.json` 和 HTML 临时文件。