Compare commits
2 Commits
copilot/fi
...
ci/gd-pr-t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fb60c0f73 | ||
|
|
c73cf3e6c2 |
160
.github/pr-modules.yml
vendored
Normal file
160
.github/pr-modules.yml
vendored
Normal file
@@ -0,0 +1,160 @@
|
||||
# 模块 → 路径匹配(globs)与 GitHub 审核人列表
|
||||
# 多模块命中时取优先级最高的为主类,其余在卡片中显示“涉及模块”
|
||||
|
||||
categories:
|
||||
ai_core:
|
||||
name: "AI Core"
|
||||
globs:
|
||||
- "packages/aiCore/**"
|
||||
- "src/renderer/src/aiCore/**"
|
||||
github_reviewers: ["DeJeune", "MyPrototypeWhat", "Vaayne"]
|
||||
|
||||
agent:
|
||||
name: "Agent"
|
||||
globs:
|
||||
- "packages/shared/agents/**"
|
||||
- "resources/data/agents-*.json"
|
||||
- "src/renderer/src/api/agent.ts"
|
||||
- "src/renderer/src/types/agent.ts"
|
||||
- "src/renderer/src/utils/agentSession.ts"
|
||||
- "src/renderer/src/services/db/AgentMessageDataSource.ts"
|
||||
- "src/renderer/src/hooks/agents/**"
|
||||
- "src/renderer/src/components/Popups/agent/**"
|
||||
- "src/renderer/src/pages/home/**/Agent*.tsx"
|
||||
- "src/renderer/src/pages/settings/AgentSettings/**"
|
||||
- "src/main/services/agents/**"
|
||||
- "src/main/apiServer/routes/agents/**"
|
||||
github_reviewers: ["EurFelux", "Vaayne", "DeJeune"]
|
||||
|
||||
provider:
|
||||
name: "Provider"
|
||||
globs:
|
||||
- "src/renderer/src/config/providers.ts"
|
||||
- "src/renderer/src/config/preprocessProviders.ts"
|
||||
- "src/renderer/src/config/webSearchProviders.ts"
|
||||
- "src/renderer/src/hooks/useWebSearchProviders.ts"
|
||||
- "src/renderer/src/providers/**"
|
||||
- "src/renderer/src/pages/settings/ProviderSettings/**"
|
||||
- "src/renderer/src/pages/settings/WebSearchSettings/**"
|
||||
- "src/renderer/src/pages/settings/DocProcessSettings/PreprocessProviderSettings.tsx"
|
||||
- "src/renderer/src/pages/settings/MCPSettings/providers/**"
|
||||
- "src/renderer/src/assets/images/providers/**"
|
||||
github_reviewers: ["YinsenHo", "kangfenmao", "alephpiece"]
|
||||
|
||||
backend:
|
||||
name: "后端/平台"
|
||||
globs:
|
||||
- "src/main/apiServer/**"
|
||||
- "src/main/services/**"
|
||||
- "src/main/*.ts"
|
||||
- "src/preload/**"
|
||||
- "src/main/mcpServers/**"
|
||||
github_reviewers: ["beyondkmp", "Vaayne", "kangfenmao"]
|
||||
|
||||
knowledge:
|
||||
name: "知识库"
|
||||
globs:
|
||||
- "src/main/knowledge/**"
|
||||
- "src/renderer/src/pages/knowledge/**"
|
||||
- "src/renderer/src/store/knowledge.ts"
|
||||
- "src/renderer/src/queue/KnowledgeQueue.ts"
|
||||
github_reviewers: ["eeee0717", "alephpiece", "GeorgeDong32"]
|
||||
|
||||
data_storage:
|
||||
name: "数据与存储"
|
||||
globs:
|
||||
- "src/renderer/src/databases/**"
|
||||
- "src/renderer/src/services/db/**"
|
||||
- "src/main/services/agents/database/**"
|
||||
- "resources/database/drizzle/**"
|
||||
- "src/renderer/src/store/migrate.ts"
|
||||
- "src/renderer/src/databases/upgrades.ts"
|
||||
github_reviewers: ["0xfullex", "kangfenmao", "Vaayne", "DeJeune"]
|
||||
|
||||
backup_export:
|
||||
name: "备份/导出"
|
||||
globs:
|
||||
- "src/renderer/src/components/*Backup*"
|
||||
- "src/renderer/src/components/Webdav*"
|
||||
- "src/renderer/src/components/ObsidianExportDialog.tsx"
|
||||
- "src/renderer/src/components/S3*"
|
||||
- "src/renderer/src/store/backup.ts"
|
||||
- "src/renderer/src/store/nutstore.ts"
|
||||
- "src/renderer/src/pages/settings/DataSettings/**"
|
||||
github_reviewers: ["beyondkmp", "GeorgeDong32"]
|
||||
|
||||
minapps:
|
||||
name: "小程序"
|
||||
globs:
|
||||
- "src/renderer/src/pages/minapps/**"
|
||||
- "src/renderer/src/store/minapps.ts"
|
||||
- "src/renderer/src/config/minapps.ts"
|
||||
github_reviewers: ["GeorgeDong32", "beyondkmp"]
|
||||
|
||||
chat:
|
||||
name: "对话"
|
||||
globs:
|
||||
- "src/renderer/src/pages/home/**"
|
||||
- "src/renderer/src/store/newMessage.ts"
|
||||
- "src/renderer/src/store/messageBlock.ts"
|
||||
- "src/renderer/src/store/memory.ts"
|
||||
- "src/renderer/src/store/llm.ts"
|
||||
github_reviewers: ["kangfenmao", "alephpiece", "EurFelux"]
|
||||
|
||||
draw:
|
||||
name: "绘图"
|
||||
globs:
|
||||
- "src/renderer/src/pages/paintings/**"
|
||||
- "src/renderer/src/store/paintings.ts"
|
||||
github_reviewers: ["EurFelux", "DeJeune"]
|
||||
|
||||
uiux:
|
||||
name: "UI/UX"
|
||||
globs:
|
||||
- "src/renderer/src/components/**"
|
||||
- "src/renderer/src/ui/**"
|
||||
- "src/renderer/src/assets/styles/**"
|
||||
- "src/renderer/src/windows/**"
|
||||
github_reviewers: ["kangfenmao", "MyPrototypeWhat", "alephpiece"]
|
||||
|
||||
build-config:
|
||||
name: "构建/配置"
|
||||
globs:
|
||||
- "package.json"
|
||||
- "tsconfig*.json"
|
||||
- "electron-builder.yml"
|
||||
- "electron.vite.config.ts"
|
||||
- "vitest.config.ts"
|
||||
- "playwright.config.ts"
|
||||
- ".github/workflows/**"
|
||||
- "scripts/**"
|
||||
github_reviewers: ["kangfenmao", "beyondkmp", "alephpiece"]
|
||||
|
||||
test:
|
||||
name: "测试"
|
||||
globs:
|
||||
- "tests/**"
|
||||
- "src/**/__tests__/**"
|
||||
- "scripts/__tests__/**"
|
||||
github_reviewers: ["alephpiece", "DeJeune", "EurFelux"]
|
||||
|
||||
docs:
|
||||
name: "文档"
|
||||
globs:
|
||||
- "docs/**"
|
||||
- "README*.md"
|
||||
- "SECURITY.md"
|
||||
- "CODE_OF_CONDUCT.md"
|
||||
- "AGENTS.md"
|
||||
github_reviewers: ["kangfenmao", "0xfullex", "EurFelux"]
|
||||
|
||||
rules:
|
||||
vendor_added:
|
||||
# 新增供应商时的强制审核人
|
||||
github_reviewers: ["YinsenHo"]
|
||||
large_change:
|
||||
# 重大变更阈值(改动文件数 > changed_files_gt 触发)
|
||||
changed_files_gt: 30
|
||||
github_reviewers: ["kangfenmao"]
|
||||
|
||||
|
||||
455
.github/reviewer-suggestions.json
vendored
Normal file
455
.github/reviewer-suggestions.json
vendored
Normal file
@@ -0,0 +1,455 @@
|
||||
{
|
||||
"generatedAt": "2025-10-29T06:19:19.098Z",
|
||||
"suggestions": {
|
||||
"ai_core": [
|
||||
{
|
||||
"github": "SuYao",
|
||||
"name": "SuYao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 33
|
||||
},
|
||||
{
|
||||
"github": "MyPrototypeWhat",
|
||||
"name": "MyPrototypeWhat",
|
||||
"email": "daoquqiexing@gmail.com",
|
||||
"commits": 12
|
||||
},
|
||||
{
|
||||
"github": "Vaayne",
|
||||
"name": "Vaayne",
|
||||
"email": "liu.vaayne@gmail.com",
|
||||
"commits": 10
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 9
|
||||
},
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 6
|
||||
}
|
||||
],
|
||||
"agent": [
|
||||
{
|
||||
"github": "icarus",
|
||||
"name": "icarus",
|
||||
"email": "eurfelux@gmail.com",
|
||||
"commits": 152
|
||||
},
|
||||
{
|
||||
"github": "Vaayne",
|
||||
"name": "Vaayne",
|
||||
"email": "liu.vaayne@gmail.com",
|
||||
"commits": 80
|
||||
},
|
||||
{
|
||||
"github": "suyao",
|
||||
"name": "suyao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 29
|
||||
},
|
||||
{
|
||||
"github": "defi-failure",
|
||||
"name": "defi-failure",
|
||||
"email": "159208748+defi-failure@users.noreply.github.com",
|
||||
"commits": 8
|
||||
},
|
||||
{
|
||||
"github": "Phantom",
|
||||
"name": "Phantom",
|
||||
"email": "eurfelux@gmail.com",
|
||||
"commits": 5
|
||||
}
|
||||
],
|
||||
"provider": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 53
|
||||
},
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 32
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 30
|
||||
},
|
||||
{
|
||||
"github": "SuYao",
|
||||
"name": "SuYao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 14
|
||||
},
|
||||
{
|
||||
"github": "eeee0717",
|
||||
"name": "Chen Tao",
|
||||
"email": "70054568+eeee0717@users.noreply.github.com",
|
||||
"commits": 10
|
||||
}
|
||||
],
|
||||
"backend": [
|
||||
{
|
||||
"github": "beyondkmp",
|
||||
"name": "beyondkmp",
|
||||
"email": "beyondkmp@gmail.com",
|
||||
"commits": 99
|
||||
},
|
||||
{
|
||||
"github": "Vaayne",
|
||||
"name": "Vaayne",
|
||||
"email": "liu.vaayne@gmail.com",
|
||||
"commits": 96
|
||||
},
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 84
|
||||
},
|
||||
{
|
||||
"github": "0xfullex",
|
||||
"name": "fullex",
|
||||
"email": "106392080+0xfullex@users.noreply.github.com",
|
||||
"commits": 49
|
||||
},
|
||||
{
|
||||
"github": "vaayne",
|
||||
"name": "LiuVaayne",
|
||||
"email": "10231735+vaayne@users.noreply.github.com",
|
||||
"commits": 33
|
||||
}
|
||||
],
|
||||
"knowledge": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 20
|
||||
},
|
||||
{
|
||||
"github": "eeee0717",
|
||||
"name": "Chen Tao",
|
||||
"email": "70054568+eeee0717@users.noreply.github.com",
|
||||
"commits": 13
|
||||
},
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 8
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 6
|
||||
},
|
||||
{
|
||||
"github": "beyondkmp",
|
||||
"name": "beyondkmp",
|
||||
"email": "beyondkmp@gmail.com",
|
||||
"commits": 5
|
||||
}
|
||||
],
|
||||
"data_storage": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 63
|
||||
},
|
||||
{
|
||||
"github": "Vaayne",
|
||||
"name": "Vaayne",
|
||||
"email": "liu.vaayne@gmail.com",
|
||||
"commits": 21
|
||||
},
|
||||
{
|
||||
"github": "SuYao",
|
||||
"name": "SuYao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 20
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 17
|
||||
},
|
||||
{
|
||||
"github": "suyao",
|
||||
"name": "suyao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 13
|
||||
}
|
||||
],
|
||||
"backup_export": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 23
|
||||
},
|
||||
{
|
||||
"github": "beyondkmp",
|
||||
"name": "beyondkmp",
|
||||
"email": "beyondkmp@gmail.com",
|
||||
"commits": 12
|
||||
},
|
||||
{
|
||||
"github": "GeorgeDong32",
|
||||
"name": "George·Dong",
|
||||
"email": "98630204+GeorgeDong32@users.noreply.github.com",
|
||||
"commits": 9
|
||||
},
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 5
|
||||
},
|
||||
{
|
||||
"github": "0xfullex",
|
||||
"name": "fullex",
|
||||
"email": "106392080+0xfullex@users.noreply.github.com",
|
||||
"commits": 5
|
||||
}
|
||||
],
|
||||
"minapps": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 12
|
||||
},
|
||||
{
|
||||
"github": "beyondkmp",
|
||||
"name": "beyondkmp",
|
||||
"email": "beyondkmp@gmail.com",
|
||||
"commits": 5
|
||||
},
|
||||
{
|
||||
"github": "GeorgeDong32",
|
||||
"name": "George·Dong",
|
||||
"email": "98630204+GeorgeDong32@users.noreply.github.com",
|
||||
"commits": 4
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 4
|
||||
},
|
||||
{
|
||||
"github": "0xfullex",
|
||||
"name": "fullex",
|
||||
"email": "106392080+0xfullex@users.noreply.github.com",
|
||||
"commits": 3
|
||||
}
|
||||
],
|
||||
"chat": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 189
|
||||
},
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 86
|
||||
},
|
||||
{
|
||||
"github": "icarus",
|
||||
"name": "icarus",
|
||||
"email": "eurfelux@gmail.com",
|
||||
"commits": 85
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 52
|
||||
},
|
||||
{
|
||||
"github": "SuYao",
|
||||
"name": "SuYao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 48
|
||||
}
|
||||
],
|
||||
"draw": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 8
|
||||
},
|
||||
{
|
||||
"github": "jin-wang-c",
|
||||
"name": "Caelan",
|
||||
"email": "79105826+jin-wang-c@users.noreply.github.com",
|
||||
"commits": 7
|
||||
},
|
||||
{
|
||||
"github": "DDU1222",
|
||||
"name": "chenxue",
|
||||
"email": "DDU1222@users.noreply.github.com",
|
||||
"commits": 6
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 5
|
||||
},
|
||||
{
|
||||
"github": "0xfullex",
|
||||
"name": "fullex",
|
||||
"email": "106392080+0xfullex@users.noreply.github.com",
|
||||
"commits": 4
|
||||
}
|
||||
],
|
||||
"uiux": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 109
|
||||
},
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 89
|
||||
},
|
||||
{
|
||||
"github": "icarus",
|
||||
"name": "icarus",
|
||||
"email": "eurfelux@gmail.com",
|
||||
"commits": 35
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 32
|
||||
},
|
||||
{
|
||||
"github": "0xfullex",
|
||||
"name": "fullex",
|
||||
"email": "106392080+0xfullex@users.noreply.github.com",
|
||||
"commits": 24
|
||||
}
|
||||
],
|
||||
"build-config": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 170
|
||||
},
|
||||
{
|
||||
"github": "beyondkmp",
|
||||
"name": "beyondkmp",
|
||||
"email": "beyondkmp@gmail.com",
|
||||
"commits": 65
|
||||
},
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 40
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 34
|
||||
},
|
||||
{
|
||||
"github": "SuYao",
|
||||
"name": "SuYao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 32
|
||||
}
|
||||
],
|
||||
"test": [
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 45
|
||||
},
|
||||
{
|
||||
"github": "SuYao",
|
||||
"name": "SuYao",
|
||||
"email": "sy20010504@gmail.com",
|
||||
"commits": 27
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 20
|
||||
},
|
||||
{
|
||||
"github": "Vaayne",
|
||||
"name": "Vaayne",
|
||||
"email": "liu.vaayne@gmail.com",
|
||||
"commits": 19
|
||||
},
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 18
|
||||
}
|
||||
],
|
||||
"docs": [
|
||||
{
|
||||
"github": "kangfenmao",
|
||||
"name": "kangfenmao",
|
||||
"email": "kangfenmao@qq.com",
|
||||
"commits": 18
|
||||
},
|
||||
{
|
||||
"github": "0xfullex",
|
||||
"name": "fullex",
|
||||
"email": "106392080+0xfullex@users.noreply.github.com",
|
||||
"commits": 7
|
||||
},
|
||||
{
|
||||
"github": "EurFelux",
|
||||
"name": "Phantom",
|
||||
"email": "59059173+EurFelux@users.noreply.github.com",
|
||||
"commits": 6
|
||||
},
|
||||
{
|
||||
"github": "one",
|
||||
"name": "one",
|
||||
"email": "wangan.cs@gmail.com",
|
||||
"commits": 6
|
||||
},
|
||||
{
|
||||
"github": "sunrise0o0",
|
||||
"name": "牡丹凤凰",
|
||||
"email": "87239270+sunrise0o0@users.noreply.github.com",
|
||||
"commits": 4
|
||||
}
|
||||
],
|
||||
"vendor_added": [],
|
||||
"large_change": []
|
||||
}
|
||||
}
|
||||
285
.github/workflows/github-pr-tracker.yml
vendored
Normal file
285
.github/workflows/github-pr-tracker.yml
vendored
Normal file
@@ -0,0 +1,285 @@
|
||||
name: GitHub PR Tracker with Feishu Notification
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, ready_for_review, review_requested, reopened]
|
||||
schedule:
|
||||
# Run every day at 8:30 Beijing Time (00:30 UTC)
|
||||
- cron: '30 0 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
process-new-pr:
|
||||
if: github.event_name == 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: read
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Check PR conditions
|
||||
id: check_pr
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const pr = context.payload.pull_request;
|
||||
|
||||
// Check if PR is draft
|
||||
if (pr.draft) {
|
||||
console.log('⏭️ PR is in draft state, skipping notification');
|
||||
core.setOutput('should_notify', 'false');
|
||||
core.setOutput('skip_reason', 'draft');
|
||||
return;
|
||||
}
|
||||
|
||||
// We will notify regardless of whether reviewers/assignees are set
|
||||
console.log('✅ PR meets notification criteria');
|
||||
core.setOutput('should_notify', 'true');
|
||||
|
||||
// Prepare reviewer and assignee lists
|
||||
const reviewers = (pr.requested_reviewers || []).map(r => r.login).join(',');
|
||||
const assignees = (pr.assignees || []).map(a => a.login).join(',');
|
||||
|
||||
core.setOutput('reviewers', reviewers);
|
||||
core.setOutput('assignees', assignees);
|
||||
|
||||
- name: Check Beijing Time
|
||||
if: steps.check_pr.outputs.should_notify == 'true'
|
||||
id: check_time
|
||||
run: |
|
||||
# Get current time in Beijing timezone (UTC+8)
|
||||
BEIJING_HOUR=$(TZ='Asia/Shanghai' date +%H)
|
||||
BEIJING_MINUTE=$(TZ='Asia/Shanghai' date +%M)
|
||||
|
||||
echo "Beijing Time: ${BEIJING_HOUR}:${BEIJING_MINUTE}"
|
||||
|
||||
# Check if time is between 00:00 and 08:30
|
||||
if [ $BEIJING_HOUR -lt 8 ] || ([ $BEIJING_HOUR -eq 8 ] && [ $BEIJING_MINUTE -le 30 ]); then
|
||||
echo "should_delay=true" >> $GITHUB_OUTPUT
|
||||
echo "⏰ PR created during quiet hours (00:00-08:30 Beijing Time)"
|
||||
echo "Will schedule notification for 08:30"
|
||||
else
|
||||
echo "should_delay=false" >> $GITHUB_OUTPUT
|
||||
echo "✅ PR created during active hours, will notify immediately"
|
||||
fi
|
||||
|
||||
- name: Add pending label if in quiet hours
|
||||
if: steps.check_pr.outputs.should_notify == 'true' && steps.check_time.outputs.should_delay == 'true'
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
const pr = context.payload.pull_request;
|
||||
github.rest.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: pr.number,
|
||||
labels: ['pending-feishu-pr-notification']
|
||||
});
|
||||
|
||||
- name: Setup Node.js
|
||||
if: steps.check_pr.outputs.should_notify == 'true' && steps.check_time.outputs.should_delay == 'false'
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Process PR with Claude
|
||||
if: steps.check_pr.outputs.should_notify == 'true' && steps.check_time.outputs.should_delay == 'false'
|
||||
uses: anthropics/claude-code-action@main
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
allowed_non_write_users: "*"
|
||||
anthropic_api_key: ${{ secrets.CLAUDE_TRANSLATOR_APIKEY }}
|
||||
claude_args: "--allowed-tools Bash(gh pr:*),Bash(node scripts/feishu-pr-notify.js)"
|
||||
prompt: |
|
||||
你是一个GitHub Pull Request自动化处理助手。请完成以下任务:
|
||||
|
||||
## 当前PR信息
|
||||
- PR编号:#${{ github.event.pull_request.number }}
|
||||
- 标题:${{ github.event.pull_request.title }}
|
||||
- 作者:${{ github.event.pull_request.user.login }}
|
||||
- URL:${{ github.event.pull_request.html_url }}
|
||||
- 内容:${{ github.event.pull_request.body }}
|
||||
- 标签:${{ join(github.event.pull_request.labels.*.name, ', ') }}
|
||||
- 改动文件数:${{ github.event.pull_request.changed_files }}
|
||||
- 增加行数:${{ github.event.pull_request.additions }}
|
||||
- 删除行数:${{ github.event.pull_request.deletions }}
|
||||
- Reviewers:${{ steps.check_pr.outputs.reviewers }}
|
||||
- Assignees:${{ steps.check_pr.outputs.assignees }}
|
||||
|
||||
## 任务步骤
|
||||
|
||||
1. **分析PR改动内容**
|
||||
首先使用以下命令获取PR的文件变更列表:
|
||||
```bash
|
||||
gh pr view ${{ github.event.pull_request.number }} --json files --jq '.files[].path'
|
||||
```
|
||||
|
||||
2. **分类PR内容**
|
||||
根据改动的文件路径和PR标题、描述,判断PR的类型(若命中多个模块则输出 `multiple`,若均未命中则 `other`):
|
||||
- chat(对话): src/renderer/src/pages/home/**, src/renderer/src/store/(newMessage|messageBlock|memory).ts
|
||||
- draw(绘图): src/renderer/src/pages/paintings/**, src/renderer/src/store/paintings.ts
|
||||
- uiux(UI/UX): src/renderer/src/components/**, src/renderer/src/ui/**, src/renderer/src/assets/styles/**, src/renderer/src/windows/**
|
||||
- knowledge(知识库): src/main/knowledge/**, src/renderer/src/pages/knowledge/**, src/renderer/src/store/knowledge.ts, src/renderer/src/queue/KnowledgeQueue.ts
|
||||
- minapps(小程序): src/renderer/src/pages/minapps/**, src/renderer/src/store/minapps.ts, src/renderer/src/config/minapps.ts
|
||||
- backup_export(备份/导出): src/renderer/src/components/*Backup*, src/renderer/src/components/Webdav*, src/renderer/src/components/ObsidianExportDialog.tsx, src/renderer/src/components/S3*, src/renderer/src/store/(backup|nutstore).ts
|
||||
- data_storage(数据与存储): src/renderer/src/databases/**, src/renderer/src/services/db/**, src/main/services/agents/database/**, resources/database/drizzle/**, src/renderer/src/store/migrate.ts, src/renderer/src/databases/upgrades.ts
|
||||
- ai_core(AI基础设施): packages/aiCore/**, src/renderer/src/aiCore/**
|
||||
- backend(后端/平台): src/main/apiServer/**, src/main/services/**, src/main/*.ts, src/preload/**, src/main/mcpServers/**
|
||||
- agent(Agent): packages/shared/agents/**, resources/data/agents-*.json, src/renderer/src/api/agent.ts, src/renderer/src/types/agent.ts, src/renderer/src/utils/agentSession.ts, src/renderer/src/services/db/AgentMessageDataSource.ts, src/renderer/src/hooks/agents/**, src/renderer/src/components/Popups/agent/**, src/renderer/src/pages/home/**/Agent*.tsx, src/renderer/src/pages/settings/AgentSettings/**, src/main/services/agents/**, src/main/apiServer/routes/agents/**
|
||||
- provider(Provider): src/renderer/src/config/(providers|preprocessProviders|webSearchProviders).ts, src/renderer/src/hooks/useWebSearchProviders.ts, src/renderer/src/providers/**, src/renderer/src/pages/settings/ProviderSettings/**, src/renderer/src/pages/settings/WebSearchSettings/**, src/renderer/src/pages/settings/DocProcessSettings/(OcrProviderSettings|PreprocessProviderSettings).tsx, src/renderer/src/pages/settings/MCPSettings/providers/**, src/renderer/src/assets/images/providers/**, src/main/services/urlschema/handle-providers.ts
|
||||
- build-config(构建/配置): package.json, tsconfig*.json, electron-builder.yml, electron.vite.config.ts, vitest.config.ts, playwright.config.ts, .github/workflows/**, scripts/**
|
||||
- test(测试): tests/**, src/**/__tests__/**, scripts/__tests__/**
|
||||
- docs(文档): docs/**, README*.md, SECURITY.md, CODE_OF_CONDUCT.md, AGENTS.md
|
||||
|
||||
2.1 **识别是否“新增供应商”**
|
||||
满足以下任一条件则视为“新增供应商”并设置变量 PR_VENDOR_ADDED=true,否则为 false:
|
||||
- 改动文件包含:
|
||||
- src/renderer/src/config/providers.ts
|
||||
- src/renderer/src/providers/**
|
||||
- packages/aiCore/**/provider/** 或 packages/aiCore/src/provider/**
|
||||
- resources/data/agents-*.json
|
||||
- 或 PR 标题/描述包含关键词:"供应商"、"厂商"、"provider"、"新增"、"集成"
|
||||
|
||||
3. **总结PR**
|
||||
用中文(简体)提供简洁的总结(2-3句话),包括:
|
||||
- PR的主要改动内容
|
||||
- 核心功能或修复
|
||||
- 重要的技术细节或影响范围
|
||||
|
||||
4. **发送飞书通知**
|
||||
使用以下命令发送飞书通知:
|
||||
```bash
|
||||
PR_URL="${{ github.event.pull_request.html_url }}" \
|
||||
PR_NUMBER="${{ github.event.pull_request.number }}" \
|
||||
PR_TITLE="${{ github.event.pull_request.title }}" \
|
||||
PR_AUTHOR="${{ github.event.pull_request.user.login }}" \
|
||||
PR_LABELS="${{ join(github.event.pull_request.labels.*.name, ',') }}" \
|
||||
PR_SUMMARY="<你生成的中文总结>" \
|
||||
PR_REVIEWERS="${{ steps.check_pr.outputs.reviewers }}" \
|
||||
PR_ASSIGNEES="${{ steps.check_pr.outputs.assignees }}" \
|
||||
PR_CATEGORY="<你判断的PR类型>" \
|
||||
PR_VENDOR_ADDED="<true 或 false>" \
|
||||
PR_CHANGED_FILES="${{ github.event.pull_request.changed_files }}" \
|
||||
PR_ADDITIONS="${{ github.event.pull_request.additions }}" \
|
||||
PR_DELETIONS="${{ github.event.pull_request.deletions }}" \
|
||||
node scripts/feishu-pr-notify.js
|
||||
```
|
||||
|
||||
## 注意事项
|
||||
- 总结必须使用简体中文
|
||||
- PR_SUMMARY 和其他参数在传递时需要正确转义特殊字符
|
||||
- PR_CATEGORY 必须是上述定义的类型之一
|
||||
- 如果PR内容为空,也要提供一个简短的说明
|
||||
|
||||
请开始执行任务!
|
||||
env:
|
||||
ANTHROPIC_BASE_URL: ${{ secrets.CLAUDE_TRANSLATOR_BASEURL }}
|
||||
FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}
|
||||
FEISHU_WEBHOOK_SECRET: ${{ secrets.FEISHU_WEBHOOK_SECRET }}
|
||||
FEISHU_USER_MAPPING: ${{ secrets.FEISHU_USER_MAPPING }}
|
||||
|
||||
process-pending-prs:
|
||||
if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch'
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: read
|
||||
id-token: write
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: '20'
|
||||
|
||||
- name: Process pending PRs with Claude
|
||||
uses: anthropics/claude-code-action@main
|
||||
with:
|
||||
anthropic_api_key: ${{ secrets.CLAUDE_TRANSLATOR_APIKEY }}
|
||||
allowed_non_write_users: "*"
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
claude_args: "--allowed-tools Bash(gh pr:*),Bash(gh api:*),Bash(node scripts/feishu-pr-notify.js)"
|
||||
prompt: |
|
||||
你是一个GitHub Pull Request自动化处理助手。请完成以下任务:
|
||||
|
||||
## 任务说明
|
||||
处理所有待发送飞书通知的GitHub PRs(标记为 `pending-feishu-pr-notification` 的PRs)
|
||||
|
||||
## 步骤
|
||||
|
||||
1. **获取待处理的PRs**
|
||||
使用以下命令获取所有带 `pending-feishu-pr-notification` 标签的PRs:
|
||||
```bash
|
||||
gh api repos/${{ github.repository }}/pulls?state=open | jq '.[] | select(.labels[]?.name == "pending-feishu-pr-notification")'
|
||||
```
|
||||
|
||||
2. **验证PR条件**
|
||||
对于每个PR,检查:
|
||||
- 是否仍然不是draft状态
|
||||
- 是否有reviewers或assignees
|
||||
- 如果不满足条件,移除标签并跳过
|
||||
|
||||
3. **分析和分类PR**
|
||||
获取PR的文件变更:
|
||||
```bash
|
||||
gh pr view <PR编号> --json files --jq '.files[].path'
|
||||
```
|
||||
|
||||
根据文件路径判断PR类型(chat/draw/uiux/knowledge/minapps/backup_export/data_storage/ai_core/backend/agent/provider/docs/build-config/test/multiple/other)
|
||||
|
||||
4. **总结每个PR**
|
||||
用中文提供简洁的总结(2-3句话),包括:
|
||||
- PR的主要改动内容
|
||||
- 核心功能或修复
|
||||
- 重要的技术细节
|
||||
|
||||
5. **发送飞书通知**
|
||||
使用以下命令发送通知:
|
||||
```bash
|
||||
PR_URL="<PR的html_url>" \
|
||||
PR_NUMBER="<PR编号>" \
|
||||
PR_TITLE="<PR标题>" \
|
||||
PR_AUTHOR="<PR作者>" \
|
||||
PR_LABELS="<逗号分隔的标签列表,排除pending-feishu-pr-notification>" \
|
||||
PR_SUMMARY="<你生成的中文总结>" \
|
||||
PR_REVIEWERS="<reviewers列表,逗号分隔>" \
|
||||
PR_ASSIGNEES="<assignees列表,逗号分隔>" \
|
||||
PR_CATEGORY="<PR类型>" \
|
||||
PR_VENDOR_ADDED="<true 或 false>" \
|
||||
PR_CHANGED_FILES="<改动文件数>" \
|
||||
PR_ADDITIONS="<增加行数>" \
|
||||
PR_DELETIONS="<删除行数>" \
|
||||
node scripts/feishu-pr-notify.js
|
||||
```
|
||||
|
||||
6. **移除标签**
|
||||
成功发送后,移除标签:
|
||||
```bash
|
||||
gh api -X DELETE repos/${{ github.repository }}/issues/<PR编号>/labels/pending-feishu-pr-notification
|
||||
```
|
||||
|
||||
## 环境变量
|
||||
- Repository: ${{ github.repository }}
|
||||
- Feishu webhook URL和密钥已配置
|
||||
|
||||
## 注意事项
|
||||
- 如果没有待处理的PRs,输出提示后结束
|
||||
- 处理多个PRs时,每个之间等待2-3秒
|
||||
- 某个PR失败不中断整个流程
|
||||
- 所有总结使用简体中文
|
||||
|
||||
请开始执行任务!
|
||||
env:
|
||||
ANTHROPIC_BASE_URL: ${{ secrets.CLAUDE_TRANSLATOR_BASEURL }}
|
||||
FEISHU_WEBHOOK_URL: ${{ secrets.FEISHU_WEBHOOK_URL }}
|
||||
FEISHU_WEBHOOK_SECRET: ${{ secrets.FEISHU_WEBHOOK_SECRET }}
|
||||
FEISHU_USER_MAPPING: ${{ secrets.FEISHU_USER_MAPPING }}
|
||||
|
||||
|
||||
635
scripts/feishu-pr-notify.js
Normal file
635
scripts/feishu-pr-notify.js
Normal file
@@ -0,0 +1,635 @@
|
||||
/**
|
||||
* Feishu (Lark) Webhook Notification Script for Pull Requests
|
||||
* Sends GitHub PR summaries to Feishu with @ mentions for reviewers and assignees
|
||||
*/
|
||||
|
||||
const crypto = require('crypto')
|
||||
const https = require('https')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
/**
|
||||
* Generate Feishu webhook signature
|
||||
* @param {string} secret - Feishu webhook secret
|
||||
* @param {number} timestamp - Unix timestamp in seconds
|
||||
* @returns {string} Base64 encoded signature
|
||||
*/
|
||||
function generateSignature(secret, timestamp) {
|
||||
const stringToSign = `${timestamp}\n${secret}`
|
||||
const hmac = crypto.createHmac('sha256', stringToSign)
|
||||
return hmac.digest('base64')
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message to Feishu webhook
|
||||
* @param {string} webhookUrl - Feishu webhook URL
|
||||
* @param {string} secret - Feishu webhook secret
|
||||
* @param {object} content - Message content
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function sendToFeishu(webhookUrl, secret, content) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timestamp = Math.floor(Date.now() / 1000)
|
||||
const sign = generateSignature(secret, timestamp)
|
||||
|
||||
const payload = JSON.stringify({
|
||||
timestamp: timestamp.toString(),
|
||||
sign: sign,
|
||||
msg_type: 'interactive',
|
||||
card: content
|
||||
})
|
||||
|
||||
const url = new URL(webhookUrl)
|
||||
const options = {
|
||||
hostname: url.hostname,
|
||||
path: url.pathname + url.search,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Content-Length': Buffer.byteLength(payload)
|
||||
}
|
||||
}
|
||||
|
||||
const req = https.request(options, (res) => {
|
||||
let data = ''
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk
|
||||
})
|
||||
res.on('end', () => {
|
||||
if (res.statusCode >= 200 && res.statusCode < 300) {
|
||||
console.log('✅ Successfully sent to Feishu:', data)
|
||||
resolve()
|
||||
} else {
|
||||
reject(new Error(`Feishu API error: ${res.statusCode} - ${data}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
req.on('error', (error) => {
|
||||
reject(error)
|
||||
})
|
||||
|
||||
req.write(payload)
|
||||
req.end()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse user mapping from environment variable
|
||||
* Expected format: "github_user1:feishu_id1,github_user2:feishu_id2"
|
||||
* @param {string} mappingStr - User mapping string
|
||||
* @returns {Map<string, string>} Map of GitHub username to Feishu user ID
|
||||
*/
|
||||
function parseUserMapping(mappingStr) {
|
||||
const mapping = new Map()
|
||||
if (!mappingStr) {
|
||||
return mapping
|
||||
}
|
||||
|
||||
const pairs = mappingStr.split(',')
|
||||
for (const pair of pairs) {
|
||||
const [github, feishu] = pair.split(':').map((s) => s.trim())
|
||||
if (github && feishu) {
|
||||
mapping.set(github, feishu)
|
||||
}
|
||||
}
|
||||
return mapping
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PR category display info
|
||||
* @param {string} category - PR category
|
||||
* @returns {object} Category display info
|
||||
*/
|
||||
function getCategoryInfo(category) {
|
||||
const categoryMap = {
|
||||
chat: { emoji: '💬', name: '对话', color: 'blue' },
|
||||
draw: { emoji: '🖼️', name: '绘图', color: 'blue' },
|
||||
uiux: { emoji: '🎨', name: 'UI/UX', color: 'blue' },
|
||||
knowledge: { emoji: '🧠', name: '知识库', color: 'green' },
|
||||
agent: { emoji: '🕹️', name: 'Agent', color: 'turquoise' },
|
||||
provider: { emoji: '🔌', name: 'Provider', color: 'turquoise' },
|
||||
minapps: { emoji: '🧩', name: '小程序', color: 'turquoise' },
|
||||
backup_export: { emoji: '💾', name: '备份/导出', color: 'purple' },
|
||||
data_storage: { emoji: '🗄️', name: '数据与存储', color: 'purple' },
|
||||
ai_core: { emoji: '🤖', name: 'AI基础设施', color: 'purple' },
|
||||
backend: { emoji: '⚙️', name: '后端/平台', color: 'green' },
|
||||
docs: { emoji: '📚', name: '文档', color: 'grey' },
|
||||
'build-config': { emoji: '🔧', name: '构建/配置', color: 'orange' },
|
||||
test: { emoji: '🧪', name: '测试', color: 'yellow' },
|
||||
multiple: { emoji: '🔀', name: '多模块', color: 'red' },
|
||||
other: { emoji: '📝', name: '其他', color: 'blue' }
|
||||
}
|
||||
|
||||
return categoryMap[category] || categoryMap.other
|
||||
}
|
||||
|
||||
/**
|
||||
* Load GitHub reviewers per category from .github/pr-modules.yml (optional)
|
||||
* Supports inline array style: github_reviewers: ["user1","user2"] or []
|
||||
* @returns {Map<string, string[]>}
|
||||
*/
|
||||
function loadConfigGithubReviewersByCategory() {
|
||||
const result = new Map()
|
||||
result.__rules = { vendor_added: [], large_change: { changed_files_gt: 30, reviewers: [] } }
|
||||
try {
|
||||
const candidates = [
|
||||
path.join(process.cwd(), '.github', 'pr-modules.yml'),
|
||||
path.join(process.cwd(), '.github', 'pr-modules.yaml')
|
||||
]
|
||||
let filePath = null
|
||||
for (const p of candidates) {
|
||||
if (fs.existsSync(p)) {
|
||||
filePath = p
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!filePath) return result
|
||||
|
||||
const content = fs.readFileSync(filePath, 'utf8')
|
||||
const lines = content.split(/\r?\n/)
|
||||
let inCategories = false
|
||||
let inRules = false
|
||||
let currentCategory = null
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i]
|
||||
if (!inCategories && !inRules) {
|
||||
if (/^categories:\s*$/.test(line)) {
|
||||
inCategories = true
|
||||
continue
|
||||
}
|
||||
if (/^rules:\s*$/.test(line)) {
|
||||
inRules = true
|
||||
continue
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if (inCategories) {
|
||||
const catMatch = /^\s{2}([a-zA-Z0-9_-]+):\s*$/.exec(line)
|
||||
if (catMatch) {
|
||||
currentCategory = catMatch[1]
|
||||
continue
|
||||
}
|
||||
|
||||
if (currentCategory) {
|
||||
const reviewersMatch = /^\s{4}github_reviewers:\s*(.*)$/.exec(line)
|
||||
if (reviewersMatch) {
|
||||
let value = (reviewersMatch[1] || '').trim()
|
||||
let users = []
|
||||
if (value.startsWith('[') && value.endsWith(']')) {
|
||||
const inner = value.slice(1, -1).trim()
|
||||
if (inner.length > 0) {
|
||||
users = inner
|
||||
.split(',')
|
||||
.map((s) => s.trim().replace(/^"|"$/g, '').replace(/^'|'$/g, ''))
|
||||
.filter(Boolean)
|
||||
}
|
||||
} else if (value === '' || value === '[]') {
|
||||
// try to parse dash list style
|
||||
const collected = []
|
||||
let j = i + 1
|
||||
while (j < lines.length) {
|
||||
const l = lines[j]
|
||||
const dash = /^\s{6}-\s*(["']?)([^"']*)\1\s*$/.exec(l)
|
||||
if (dash) {
|
||||
const user = dash[2].trim()
|
||||
if (user) collected.push(user)
|
||||
j++
|
||||
continue
|
||||
}
|
||||
break
|
||||
}
|
||||
users = collected
|
||||
}
|
||||
result.set(currentCategory, Array.from(new Set(users)))
|
||||
}
|
||||
}
|
||||
} else if (inRules) {
|
||||
// vendor_added block
|
||||
if (/^\s{2}vendor_added:\s*$/.test(line)) {
|
||||
// parse github_reviewers under vendor_added
|
||||
let j = i + 1
|
||||
const reviewers = []
|
||||
while (j < lines.length) {
|
||||
const l = lines[j]
|
||||
const reviewersLine = /^\s{4}github_reviewers:\s*(.*)$/.exec(l)
|
||||
if (reviewersLine) {
|
||||
let value = (reviewersLine[1] || '').trim()
|
||||
if (value.startsWith('[') && value.endsWith(']')) {
|
||||
const inner = value.slice(1, -1).trim()
|
||||
if (inner.length > 0) {
|
||||
inner.split(',').forEach((s) => {
|
||||
const u = s.trim().replace(/^"|"$/g, '').replace(/^'|'$/g, '')
|
||||
if (u) reviewers.push(u)
|
||||
})
|
||||
}
|
||||
}
|
||||
j++
|
||||
continue
|
||||
}
|
||||
const dash = /^\s{6}-\s*(["']?)([^"']*)\1\s*$/.exec(l)
|
||||
if (dash) {
|
||||
const u = dash[2].trim()
|
||||
if (u) reviewers.push(u)
|
||||
j++
|
||||
continue
|
||||
}
|
||||
if (/^\s{2}[a-zA-Z0-9_-]+:\s*$/.test(l)) break
|
||||
j++
|
||||
}
|
||||
result.__rules.vendor_added = Array.from(new Set(reviewers))
|
||||
}
|
||||
|
||||
// large_change block
|
||||
if (/^\s{2}large_change:\s*$/.test(line)) {
|
||||
let j = i + 1
|
||||
const rule = { changed_files_gt: 30, reviewers: [] }
|
||||
while (j < lines.length) {
|
||||
const l = lines[j]
|
||||
const threshold = /^\s{4}changed_files_gt:\s*(\d+)\s*$/.exec(l)
|
||||
if (threshold) {
|
||||
rule.changed_files_gt = parseInt(threshold[1], 10)
|
||||
j++
|
||||
continue
|
||||
}
|
||||
const reviewersLine = /^\s{4}github_reviewers:\s*(.*)$/.exec(l)
|
||||
if (reviewersLine) {
|
||||
let value = (reviewersLine[1] || '').trim()
|
||||
if (value.startsWith('[') && value.endsWith(']')) {
|
||||
const inner = value.slice(1, -1).trim()
|
||||
if (inner.length > 0) {
|
||||
inner.split(',').forEach((s) => {
|
||||
const u = s.trim().replace(/^"|"$/g, '').replace(/^'|'$/g, '')
|
||||
if (u) rule.reviewers.push(u)
|
||||
})
|
||||
}
|
||||
}
|
||||
j++
|
||||
continue
|
||||
}
|
||||
const dash = /^\s{6}-\s*(["']?)([^"']*)\1\s*$/.exec(l)
|
||||
if (dash) {
|
||||
const u = dash[2].trim()
|
||||
if (u) rule.reviewers.push(u)
|
||||
j++
|
||||
continue
|
||||
}
|
||||
if (/^\s{2}[a-zA-Z0-9_-]+:\s*$/.test(l)) break
|
||||
j++
|
||||
}
|
||||
rule.reviewers = Array.from(new Set(rule.reviewers))
|
||||
result.__rules.large_change = rule
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('⚠️ Failed to load .github/pr-modules.yml:', e.message)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recommended reviewers based on PR category
|
||||
* This is a helper for Claude to suggest appropriate reviewers
|
||||
* @param {string} category - PR category
|
||||
* @param {Map<string, string>} userMapping - GitHub to Feishu user mapping
|
||||
* @returns {string[]} List of Feishu user IDs to notify
|
||||
*/
|
||||
function getRecommendedReviewersByCategory(category, userMapping, configGithubReviewersMap) {
|
||||
// Fallback mapping when config not provided
|
||||
const fallback = {
|
||||
backend: ['kangfenmao'],
|
||||
ai_core: ['kangfenmao'],
|
||||
'build-config': ['kangfenmao'],
|
||||
multiple: ['kangfenmao']
|
||||
}
|
||||
|
||||
const configUsers = (configGithubReviewersMap && configGithubReviewersMap.get(category)) || []
|
||||
const fallbackUsers = fallback[category] || []
|
||||
const githubUsers = Array.from(new Set([...configUsers, ...fallbackUsers]))
|
||||
return githubUsers.map((gh) => userMapping.get(gh)).filter(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Feishu card message from PR data
|
||||
* @param {object} prData - GitHub PR data
|
||||
* @param {Map<string, string>} userMapping - GitHub to Feishu user mapping
|
||||
* @returns {object} Feishu card content
|
||||
*/
|
||||
function createPRCard(prData, userMapping, configGithubReviewersMap) {
|
||||
const {
|
||||
prUrl,
|
||||
prNumber,
|
||||
prTitle,
|
||||
prSummary,
|
||||
prAuthor,
|
||||
labels,
|
||||
reviewers,
|
||||
assignees,
|
||||
category,
|
||||
changedFiles,
|
||||
additions,
|
||||
deletions,
|
||||
vendorAdded
|
||||
} = prData
|
||||
|
||||
const categoryInfo = getCategoryInfo(category)
|
||||
|
||||
// Build labels section
|
||||
const labelElements =
|
||||
labels && labels.length > 0
|
||||
? [
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**🏷️ Labels:** ${labels.map((l) => `\`${l}\``).join(' ')}`
|
||||
}
|
||||
}
|
||||
]
|
||||
: []
|
||||
|
||||
// Build stats section
|
||||
const statsContent = [
|
||||
`📁 ${changedFiles || 0} files`,
|
||||
`<font color='green'>+${additions || 0}</font>`,
|
||||
`<font color='red'>-${deletions || 0}</font>`
|
||||
].join(' · ')
|
||||
|
||||
// Build mention content for reviewers and assignees
|
||||
const mentions = []
|
||||
const mentionedUsers = new Set()
|
||||
|
||||
// Add reviewers
|
||||
if (reviewers && reviewers.length > 0) {
|
||||
reviewers.forEach((reviewer) => {
|
||||
const feishuId = userMapping.get(reviewer)
|
||||
if (feishuId && !mentionedUsers.has(feishuId)) {
|
||||
mentions.push(`<at id="${feishuId}"></at>`)
|
||||
mentionedUsers.add(feishuId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Add assignees
|
||||
if (assignees && assignees.length > 0) {
|
||||
assignees.forEach((assignee) => {
|
||||
const feishuId = userMapping.get(assignee)
|
||||
if (feishuId && !mentionedUsers.has(feishuId)) {
|
||||
mentions.push(`<at id="${feishuId}"></at>`)
|
||||
mentionedUsers.add(feishuId)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Add category-based experts (if not already mentioned)
|
||||
const categoryExperts = getRecommendedReviewersByCategory(category, userMapping, configGithubReviewersMap)
|
||||
categoryExperts.forEach((feishuId) => {
|
||||
if (feishuId && !mentionedUsers.has(feishuId)) {
|
||||
mentions.push(`<at id="${feishuId}"></at>`)
|
||||
mentionedUsers.add(feishuId)
|
||||
}
|
||||
})
|
||||
|
||||
// Enforce mandatory reviewers based on rules
|
||||
const mandatoryGithubUsers = []
|
||||
const rules = configGithubReviewersMap.__rules || {
|
||||
vendor_added: [],
|
||||
large_change: { changed_files_gt: 30, reviewers: [] }
|
||||
}
|
||||
if (vendorAdded) {
|
||||
mandatoryGithubUsers.push(...(rules.vendor_added || ['Yinsen-Ho']))
|
||||
}
|
||||
const changedFilesNum = Number(changedFiles) || 0
|
||||
const threshold = (rules.large_change && rules.large_change.changed_files_gt) || 30
|
||||
if (changedFilesNum > threshold) {
|
||||
const reviewers = (rules.large_change && rules.large_change.reviewers) || ['kangfenmao']
|
||||
mandatoryGithubUsers.push(...reviewers)
|
||||
}
|
||||
|
||||
mandatoryGithubUsers.forEach((gh) => {
|
||||
const feishuId = userMapping.get(gh)
|
||||
if (feishuId && !mentionedUsers.has(feishuId)) {
|
||||
mentions.push(`<at id="${feishuId}"></at>`)
|
||||
mentionedUsers.add(feishuId)
|
||||
}
|
||||
})
|
||||
|
||||
// Build mentions section
|
||||
const mentionElements =
|
||||
mentions.length > 0
|
||||
? [
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**👥 请关注:** ${mentions.join(' ')}`
|
||||
}
|
||||
}
|
||||
]
|
||||
: []
|
||||
|
||||
// Build reviewer and assignee info
|
||||
const reviewerInfo = []
|
||||
if (reviewers && reviewers.length > 0) {
|
||||
reviewerInfo.push({
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**👀 Reviewers:** ${reviewers.map((r) => `\`${r}\``).join(', ')}`
|
||||
}
|
||||
})
|
||||
}
|
||||
if (assignees && assignees.length > 0) {
|
||||
reviewerInfo.push({
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**👤 Assignees:** ${assignees.map((a) => `\`${a}\``).join(', ')}`
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
elements: [
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**🔀 New Pull Request #${prNumber}**`
|
||||
}
|
||||
},
|
||||
{
|
||||
tag: 'hr'
|
||||
},
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**${categoryInfo.emoji} 类型:** ${categoryInfo.name}`
|
||||
}
|
||||
},
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**📝 Title:** ${prTitle}`
|
||||
}
|
||||
},
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**👤 Author:** \`${prAuthor}\``
|
||||
}
|
||||
},
|
||||
...reviewerInfo,
|
||||
...labelElements,
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**📊 Changes:** ${statsContent}`
|
||||
}
|
||||
},
|
||||
{
|
||||
tag: 'hr'
|
||||
},
|
||||
{
|
||||
tag: 'div',
|
||||
text: {
|
||||
tag: 'lark_md',
|
||||
content: `**📋 Summary:**\n${prSummary}`
|
||||
}
|
||||
},
|
||||
...mentionElements,
|
||||
{
|
||||
tag: 'hr'
|
||||
},
|
||||
{
|
||||
tag: 'action',
|
||||
actions: [
|
||||
{
|
||||
tag: 'button',
|
||||
text: {
|
||||
tag: 'plain_text',
|
||||
content: '🔗 View PR'
|
||||
},
|
||||
type: 'primary',
|
||||
url: prUrl
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
header: {
|
||||
template: categoryInfo.color,
|
||||
title: {
|
||||
tag: 'plain_text',
|
||||
content: `${categoryInfo.emoji} Cherry Studio - New PR [${categoryInfo.name}]`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
async function main() {
|
||||
try {
|
||||
// Get environment variables
|
||||
const webhookUrl = process.env.FEISHU_WEBHOOK_URL
|
||||
const secret = process.env.FEISHU_WEBHOOK_SECRET
|
||||
const userMappingStr = process.env.FEISHU_USER_MAPPING || ''
|
||||
|
||||
const prUrl = process.env.PR_URL
|
||||
const prNumber = process.env.PR_NUMBER
|
||||
const prTitle = process.env.PR_TITLE
|
||||
const prSummary = process.env.PR_SUMMARY
|
||||
const prAuthor = process.env.PR_AUTHOR
|
||||
const labelsStr = process.env.PR_LABELS || ''
|
||||
const reviewersStr = process.env.PR_REVIEWERS || ''
|
||||
const assigneesStr = process.env.PR_ASSIGNEES || ''
|
||||
const category = process.env.PR_CATEGORY || 'multiple'
|
||||
const vendorAdded = String(process.env.PR_VENDOR_ADDED || 'false').toLowerCase() === 'true'
|
||||
const changedFiles = process.env.PR_CHANGED_FILES || '0'
|
||||
const additions = process.env.PR_ADDITIONS || '0'
|
||||
const deletions = process.env.PR_DELETIONS || '0'
|
||||
|
||||
// Validate required environment variables
|
||||
if (!webhookUrl) {
|
||||
throw new Error('FEISHU_WEBHOOK_URL environment variable is required')
|
||||
}
|
||||
if (!secret) {
|
||||
throw new Error('FEISHU_WEBHOOK_SECRET environment variable is required')
|
||||
}
|
||||
if (!prUrl || !prNumber || !prTitle || !prSummary) {
|
||||
throw new Error('PR data environment variables are required')
|
||||
}
|
||||
|
||||
// Parse data
|
||||
const userMapping = parseUserMapping(userMappingStr)
|
||||
const configGithubReviewersMap = loadConfigGithubReviewersByCategory()
|
||||
|
||||
const labels = labelsStr
|
||||
? labelsStr
|
||||
.split(',')
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean)
|
||||
: []
|
||||
|
||||
const reviewers = reviewersStr
|
||||
? reviewersStr
|
||||
.split(',')
|
||||
.map((r) => r.trim())
|
||||
.filter(Boolean)
|
||||
: []
|
||||
|
||||
const assignees = assigneesStr
|
||||
? assigneesStr
|
||||
.split(',')
|
||||
.map((a) => a.trim())
|
||||
.filter(Boolean)
|
||||
: []
|
||||
|
||||
// Create PR data object
|
||||
const prData = {
|
||||
prUrl,
|
||||
prNumber,
|
||||
prTitle,
|
||||
prSummary,
|
||||
prAuthor: prAuthor || 'Unknown',
|
||||
labels,
|
||||
reviewers,
|
||||
assignees,
|
||||
category,
|
||||
vendorAdded,
|
||||
changedFiles,
|
||||
additions,
|
||||
deletions
|
||||
}
|
||||
|
||||
console.log('📤 Sending PR notification to Feishu...')
|
||||
console.log(`PR #${prNumber}: ${prTitle}`)
|
||||
console.log(`Category: ${category}`)
|
||||
console.log(`Vendor added: ${vendorAdded}`)
|
||||
console.log(`Reviewers: ${reviewers.join(', ') || 'None'}`)
|
||||
console.log(`Assignees: ${assignees.join(', ') || 'None'}`)
|
||||
console.log(`User mapping entries: ${userMapping.size}`)
|
||||
|
||||
// Create card content
|
||||
const card = createPRCard(prData, userMapping, configGithubReviewersMap)
|
||||
|
||||
// Send to Feishu
|
||||
await sendToFeishu(webhookUrl, secret, card)
|
||||
|
||||
console.log('✅ PR notification sent successfully!')
|
||||
} catch (error) {
|
||||
console.error('❌ Error:', error.message)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// Run main function
|
||||
main()
|
||||
277
scripts/stats-contributors.js
Normal file
277
scripts/stats-contributors.js
Normal file
@@ -0,0 +1,277 @@
|
||||
/**
|
||||
* Stats major contributors per module based on .github/pr-modules.yml
|
||||
* Output a markdown summary and write JSON to .github/reviewer-suggestions.json
|
||||
*
|
||||
* Usage:
|
||||
* node scripts/stats-contributors.js [--top 3] [--since 1.year] [--mode auto|shortlog|log|blame] [--blame-sample 30]
|
||||
*/
|
||||
|
||||
const { spawnSync } = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
function readText(file) {
|
||||
try {
|
||||
return fs.readFileSync(file, 'utf8')
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function parseArgs() {
|
||||
const args = process.argv.slice(2)
|
||||
const out = { top: 3, since: '', mode: 'auto', blameSample: 30 }
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
if (args[i] === '--top' && i + 1 < args.length) {
|
||||
out.top = parseInt(args[++i], 10) || 3
|
||||
} else if (args[i] === '--since' && i + 1 < args.length) {
|
||||
out.since = String(args[++i])
|
||||
} else if (args[i] === '--mode' && i + 1 < args.length) {
|
||||
out.mode = String(args[++i])
|
||||
} else if (args[i] === '--blame-sample' && i + 1 < args.length) {
|
||||
out.blameSample = parseInt(args[++i], 10) || 30
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// Minimal YAML parser for categories/globs in .github/pr-modules.yml
|
||||
function parseModulesConfig(configPath) {
|
||||
const text = readText(configPath)
|
||||
if (!text) throw new Error(`Cannot read ${configPath}`)
|
||||
const lines = text.split(/\r?\n/)
|
||||
const categories = []
|
||||
let inCategories = false
|
||||
let current = null
|
||||
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i]
|
||||
if (!inCategories) {
|
||||
if (/^categories:\s*$/.test(line)) inCategories = true
|
||||
continue
|
||||
}
|
||||
|
||||
// New category key
|
||||
const catMatch = /^\s{2}([a-zA-Z0-9_-]+):\s*$/.exec(line)
|
||||
if (catMatch) {
|
||||
if (current) categories.push(current)
|
||||
current = { key: catMatch[1], name: '', globs: [] }
|
||||
continue
|
||||
}
|
||||
|
||||
if (!current) continue
|
||||
|
||||
const nameMatch = /^\s{4}name:\s*"?([^"]+)"?\s*$/.exec(line)
|
||||
if (nameMatch) {
|
||||
current.name = nameMatch[1].trim()
|
||||
continue
|
||||
}
|
||||
|
||||
// Enter globs list, then collect dash items
|
||||
const globsHeader = /^\s{4}globs:\s*$/.exec(line)
|
||||
if (globsHeader) {
|
||||
let j = i + 1
|
||||
while (j < lines.length) {
|
||||
const l = lines[j]
|
||||
const item = /^\s{6}-\s*"?([^"]+)"?\s*$/.exec(l)
|
||||
if (!item) break
|
||||
current.globs.push(item[1].trim())
|
||||
j++
|
||||
}
|
||||
continue
|
||||
}
|
||||
}
|
||||
if (current) categories.push(current)
|
||||
return categories
|
||||
}
|
||||
|
||||
function git(args, cwd) {
|
||||
const res = spawnSync('git', args, { cwd, encoding: 'utf8' })
|
||||
if (res.status !== 0) {
|
||||
const msg = (res.stderr || '').trim() || `git ${args.join(' ')} failed`
|
||||
throw new Error(msg)
|
||||
}
|
||||
return res.stdout
|
||||
}
|
||||
|
||||
function buildPathspecs(globs) {
|
||||
// Use pathspec magic :(glob)pattern so that ** works and we avoid shell expansion
|
||||
return globs.map((g) => `:(glob)${g}`)
|
||||
}
|
||||
|
||||
function lsFilesForGlobs(globs, repoRoot) {
|
||||
const pathspecs = buildPathspecs(globs)
|
||||
if (pathspecs.length === 0) return []
|
||||
try {
|
||||
const stdout = git(['ls-files', '--', ...pathspecs], repoRoot)
|
||||
return stdout
|
||||
.split(/\r?\n/)
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean)
|
||||
} catch (e) {
|
||||
// No matched files or pathspec error → treat as empty
|
||||
return []
|
||||
}
|
||||
}
|
||||
|
||||
function shortlogFor(globs, repoRoot, since) {
|
||||
const files = lsFilesForGlobs(globs, repoRoot)
|
||||
if (files.length === 0) return []
|
||||
const base = ['shortlog', '-sne']
|
||||
if (since) base.push(`--since=${since}`)
|
||||
const stdout = git([...base, '--', ...files], repoRoot)
|
||||
const lines = stdout
|
||||
.split(/\r?\n/)
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean)
|
||||
const rows = []
|
||||
for (const l of lines) {
|
||||
// e.g. " 42 John Doe <john@example.com>"
|
||||
const m = /^(\d+)\s+(.+?)\s+<([^>]+)>$/.exec(l)
|
||||
if (!m) continue
|
||||
const commits = parseInt(m[1], 10)
|
||||
const name = m[2]
|
||||
const email = m[3]
|
||||
const gh = extractGithubUsername(name, email)
|
||||
rows.push({ commits, name, email, github: gh })
|
||||
}
|
||||
rows.sort((a, b) => b.commits - a.commits)
|
||||
return rows
|
||||
}
|
||||
|
||||
function logAuthorsFor(globs, repoRoot, since) {
|
||||
const files = lsFilesForGlobs(globs, repoRoot)
|
||||
if (files.length === 0) return []
|
||||
const base = ['log', '--format=%an <%ae>']
|
||||
if (since) base.push(`--since=${since}`)
|
||||
const stdout = git([...base, '--', ...files], repoRoot)
|
||||
const lines = stdout
|
||||
.split(/\r?\n/)
|
||||
.map((l) => l.trim())
|
||||
.filter(Boolean)
|
||||
const map = new Map()
|
||||
for (const l of lines) {
|
||||
const m = /^(.+?)\s+<([^>]+)>$/.exec(l)
|
||||
if (!m) continue
|
||||
const name = m[1]
|
||||
const email = m[2]
|
||||
const gh = extractGithubUsername(name, email)
|
||||
const key = `${name} <${email}>`
|
||||
map.set(key, (map.get(key) || 0) + 1)
|
||||
}
|
||||
const out = []
|
||||
for (const [key, commits] of map.entries()) {
|
||||
const m = /^(.+?)\s+<([^>]+)>$/.exec(key)
|
||||
out.push({ commits, name: m[1], email: m[2], github: extractGithubUsername(m[1], m[2]) })
|
||||
}
|
||||
out.sort((a, b) => b.commits - a.commits)
|
||||
return out
|
||||
}
|
||||
|
||||
function blameAuthorsSample(globs, repoRoot, sample) {
|
||||
const files = lsFilesForGlobs(globs, repoRoot)
|
||||
if (files.length === 0) return []
|
||||
const pick = files.slice(0, Math.max(1, sample))
|
||||
const map = new Map()
|
||||
for (const f of pick) {
|
||||
let stdout = ''
|
||||
try {
|
||||
stdout = git(['blame', '--line-porcelain', '--', f], repoRoot)
|
||||
} catch (e) {
|
||||
continue
|
||||
}
|
||||
const lines = stdout.split(/\r?\n/)
|
||||
for (const line of lines) {
|
||||
// author and author-mail lines
|
||||
const am = /^author-mail\s+<([^>]+)>$/.exec(line)
|
||||
if (am) {
|
||||
const email = am[1]
|
||||
// We do not rely on index; we just keep email-based identity
|
||||
const gh = extractGithubUsername('', email)
|
||||
const key = `${gh || ''}<${email}>`
|
||||
map.set(key, (map.get(key) || 0) + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
const out = []
|
||||
for (const [key, commits] of map.entries()) {
|
||||
const m = /^(.*?)<([^>]+)>$/.exec(key)
|
||||
const email = m ? m[2] : ''
|
||||
const gh = extractGithubUsername('', email)
|
||||
out.push({ commits, name: gh || email, email, github: gh })
|
||||
}
|
||||
out.sort((a, b) => b.commits - a.commits)
|
||||
return out
|
||||
}
|
||||
|
||||
function extractGithubUsername(name, email) {
|
||||
// Try noreply forms: 12345+user@users.noreply.github.com or user@users.noreply.github.com
|
||||
const noreply = /^(?:\d+\+)?([A-Za-z0-9-]+)@users\.noreply\.github\.com$/.exec(email)
|
||||
if (noreply) return noreply[1]
|
||||
// If name itself looks like a probable GitHub handle
|
||||
if (/^[A-Za-z0-9-]{3,}$/.test(name)) return name
|
||||
return ''
|
||||
}
|
||||
|
||||
function main() {
|
||||
const repoRoot = process.cwd()
|
||||
const { top, since, mode, blameSample } = parseArgs()
|
||||
const configPath = path.join(repoRoot, '.github', 'pr-modules.yml')
|
||||
const categories = parseModulesConfig(configPath)
|
||||
|
||||
const suggestions = {}
|
||||
const markdownLines = []
|
||||
markdownLines.push('| Module | Top Contributors (commits) |')
|
||||
markdownLines.push('|---|---|')
|
||||
|
||||
for (const cat of categories) {
|
||||
let rows = []
|
||||
try {
|
||||
if (mode === 'shortlog' || mode === 'auto') rows = shortlogFor(cat.globs, repoRoot, since)
|
||||
if (rows.length === 0 && (mode === 'log' || mode === 'auto')) rows = logAuthorsFor(cat.globs, repoRoot, since)
|
||||
if (rows.length === 0 && (mode === 'blame' || mode === 'auto'))
|
||||
rows = blameAuthorsSample(cat.globs, repoRoot, blameSample)
|
||||
} catch (e) {
|
||||
// Fallback to next method if one fails
|
||||
if (mode === 'auto') {
|
||||
try {
|
||||
rows = logAuthorsFor(cat.globs, repoRoot, since)
|
||||
} catch (e2) {
|
||||
// ignore and continue
|
||||
}
|
||||
if (rows.length === 0) {
|
||||
try {
|
||||
rows = blameAuthorsSample(cat.globs, repoRoot, blameSample)
|
||||
} catch (e3) {
|
||||
// ignore and continue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Non-auto mode: report empty on error
|
||||
rows = []
|
||||
}
|
||||
}
|
||||
const topRows = rows.slice(0, top)
|
||||
suggestions[cat.key] = topRows.map((r) => ({
|
||||
github: r.github,
|
||||
name: r.name,
|
||||
email: r.email,
|
||||
commits: r.commits
|
||||
}))
|
||||
const cell = topRows
|
||||
.map((r) => {
|
||||
const id = r.github ? `@${r.github}` : r.name
|
||||
return `${id} (${r.commits})`
|
||||
})
|
||||
.join(', ')
|
||||
markdownLines.push(`| ${cat.key} | ${cell || '-'} |`)
|
||||
}
|
||||
|
||||
const outJsonPath = path.join(repoRoot, '.github', 'reviewer-suggestions.json')
|
||||
fs.writeFileSync(outJsonPath, JSON.stringify({ generatedAt: new Date().toISOString(), suggestions }, null, 2))
|
||||
|
||||
console.log(markdownLines.join('\n'))
|
||||
console.log(`\nSaved JSON: ${path.relative(repoRoot, outJsonPath)}`)
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user