Files
sanguo_vnpy_v2/.claude/workflows/helpers/gitea-rules-generator.js
T
claude_dev 918bbed0fc fix: 修复登录500错误和移除明文密码提示
- 修复 deps.py 中 get_vn_service 的引用错误 (vn_service.vn_service -> vn_service)
- 移除登录页面上的明文密码提示
- 改进前端错误处理,避免数据加载失败导致登录显示错误
2026-07-02 12:23:55 +08:00

250 lines
5.0 KiB
JavaScript

/**
* Gitea 规则生成器
*
* 根据配置文件动态生成 Gitea 协作规则
*/
import fs from 'fs'
import path from 'path'
/**
* 读取配置文件
*/
function loadConfig() {
const configPath = path.join(process.cwd(), '.claude', 'gitea-config.json')
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'))
return config
}
/**
* 生成 Gitea URL
*/
function getGiteaUrl(config) {
const { baseUrl, owner, repo } = config.gitea
return `${baseUrl}/${owner}/${repo}`
}
/**
* 生成 Gitea 规则字符串
*/
export function generateGiteaRules(config = null) {
if (!config) {
config = loadConfig()
}
const { baseUrl, owner, repo, defaultBranch } = config.gitea
const { branchNaming, commitNaming, prTemplate } = config.rules
const { checklist, approval } = config.review
return `
# Gitea 协作规则
## 仓库信息
- **Base URL**: ${baseUrl}
- **Owner**: ${owner}
- **Repository**: ${repo}
- **URL**: ${getGiteaUrl(config)}
- **主分支**: ${defaultBranch}
## 分支命名规则
| 类型 | 格式 | 示例 |
|------|------|------|
| 功能开发 | ${branchNaming.feature} | feature/login-api |
| 问题修复 | ${branchNaming.fix} | fix/123-auth-error |
| 紧急修复 | ${branchNaming.hotfix} | hotfix/security-patch |
## Commit 命名规则
| 类型 | 格式 | 示例 |
|------|------|------|
| 功能 | ${commitNaming.feature} | feat: 添加用户登录 |
| 修复 | ${commitNaming.fix} | fix: 修复认证 bug |
| 重构 | ${commitNaming.refactor} | refactor: 优化 API 结构 |
| 文档 | ${commitNaming.docs} | docs: 更新 API 文档 |
| 测试 | ${commitNaming.test} | test: 添加认证测试 |
## Execute Sub Agent 工作流程
### 1. 准备阶段
\`\`\`bash
# Clone 仓库
git clone ${getGiteaUrl(config)}.git
cd ${repo}
# 创建功能分支
git checkout -b ${branchNaming.feature}
\`\`\`
### 2. 实现阶段
- 根据任务要求实现代码
- 编写单元测试
- 本地测试验证
### 3. 提交阶段
\`\`\`bash
git add .
git commit -m "${commitNaming.feature}"
git push -u origin ${branchNaming.feature}
\`\`\`
### 4. PR 阶段
- 在 Gitea 上创建 Pull Request
- 标题格式: \`${prTemplate.title}\`
- 描述模板:
\`\`\`
${prTemplate.description}
\`\`\`
## Review Sub Agent 工作流程
### 1. 审查准备
- 阅读 PR 代码变更
- 检查以下项目:
${checklist.map((item, i) => ` ${i + 1}. ${item}`).join('\n')}
### 2. 添加 Review
- 在 Gitea PR 页面添加 Review 评论
- 标注有问题的代码行
- 提供具体的修改建议
- 返回 Review 结果:
\`\`\`json
{
"passed": true|false,
"findings": ["问题1", "问题2"],
"suggestions": ["建议1", "建议2"],
"approval": "${approval}"
}
\`\`\`
## Test Sub Agent 工作流程
### 1. 测试准备
- 读取 PR 代码
- 理解功能需求
### 2. 编写测试
- 单元测试
- 集成测试
- E2E 测试(如需要)
### 3. 执行测试
\`\`\`bash
npm test
# 或
pytest
\`\`\`
### 4. 报告结果
- 返回测试结果:
\`\`\`json
{
"passed": true|false,
"coverage": "85%",
"failures": [],
"summary": "测试结果摘要"
}
\`\`\`
## 修复工作流程
### 1. 接收 Review
- 阅读 PR 中的 Review 评论
- 理解问题所在
### 2. 修复问题
\`\`\`bash
# 在 PR 分支上修复
git checkout ${branchNaming.feature}
# 进行修复
\`\`\`
### 3. 提交修复
\`\`\`bash
git add .
git commit -m "${commitNaming.fix}"
git push
\`\`\`
### 4. 回复 Review
- 在 PR 中回复 Review 评论
- 说明修复内容
## 所有 Agent 共享规则
### 通过 Gitea 读取上下文
- Commit 历史 = 上下文历史
- PR 变更 = 代码变更
- Review 评论 = 审查意见
- Issues = 任务记录
### 通过 Gitea 传递结果
- Push 代码 = 传递实现结果
- 创建 PR = 请求审查
- Review 评论 = 传递审查结果
- 合并 PR = 验收完成
## 注意事项
1. **分支隔离**: 每个任务在独立分支上开发
2. **提交清晰**: Commit 信息要清晰描述变更
3. **PR 完整**: PR 描述要包含任务、方案、测试
4. **Review 及时**: 及时响应 Review 评论
5. **测试充分**: 确保测试覆盖充分
## 配置来源
本规则由以下配置生成:
- 配置文件: .claude/gitea-config.json
- 生成时间: ${new Date().toISOString()}
`
}
/**
* 获取仓库 URL
*/
export function getRepoUrl(config = null) {
if (!config) {
config = loadConfig()
}
return getGiteaUrl(config)
}
/**
* 获取分支名称
*/
export function getBranchName(type, name, config = null) {
if (!config) {
config = loadConfig()
}
const template = config.rules.branchNaming[type] || 'feature/{name}'
return template.replace('{name}', name).replace('{task-name}', name)
}
/**
* 获取 Commit 模板
*/
export function getCommitTemplate(type, config = null) {
if (!config) {
config = loadConfig()
}
return config.rules.commitNaming[type] || '{description}'
}
/**
* 获取 PR 模板
*/
export function getPrTemplate(config = null) {
if (!config) {
config = loadConfig()
}
return config.rules.prTemplate
}
// 导出默认函数
export default function generateRules(config = null) {
return generateGiteaRules(config)
}