From 0e5855ee4eb4ae77f6f53c97b71fb1c507a96a75 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:16:05 +0800 Subject: [PATCH 01/11] =?UTF-8?q?ci:=20=E6=B7=BB=E5=8A=A0=20AI=20Issue=20?= =?UTF-8?q?=E6=99=BA=E8=83=BD=E5=88=86=E6=9E=90=E5=92=8C=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-batch-analyze-issues.yml | 73 ++++++++ .github/workflows/ai-issue-helper.yml | 50 ++++++ .github/workflows/ai-issue-moderator.yml | 65 +++++++ .github/workflows/batch-label-issues.yml | 162 ++++++++++++++++++ 4 files changed, 350 insertions(+) create mode 100644 .github/workflows/ai-batch-analyze-issues.yml create mode 100644 .github/workflows/ai-issue-helper.yml create mode 100644 .github/workflows/ai-issue-moderator.yml create mode 100644 .github/workflows/batch-label-issues.yml diff --git a/.github/workflows/ai-batch-analyze-issues.yml b/.github/workflows/ai-batch-analyze-issues.yml new file mode 100644 index 00000000..c81c0c08 --- /dev/null +++ b/.github/workflows/ai-batch-analyze-issues.yml @@ -0,0 +1,73 @@ +name: AI Batch Analyze Issues + +on: + workflow_dispatch: + inputs: + mode: + description: '分析模式' + required: true + type: choice + options: + - 'recent' # 最近 10 个 issue + - 'open' # 所有打开的 issue + - 'all' # 所有 issue(慎用) + default: 'recent' + +permissions: + issues: write + contents: read + +jobs: + analyze: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + + - name: Install GitHub CLI + run: | + gh --version || (curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg + echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null + sudo apt update + sudo apt install gh) + + - name: Batch Analyze Issues + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + MODE="${{ github.event.inputs.mode }}" + + # 获取 issue 列表 + if [ "$MODE" = "recent" ]; then + echo "📊 分析最近 10 个 issue..." + ISSUES=$(gh issue list --limit 10 --json number --jq '.[].number') + elif [ "$MODE" = "open" ]; then + echo "📊 分析所有打开的 issue..." + ISSUES=$(gh issue list --state open --json number --jq '.[].number') + else + echo "📊 分析所有 issue(这可能需要很长时间)..." + ISSUES=$(gh issue list --state all --limit 100 --json number --jq '.[].number') + fi + + # 为每个 issue 添加 AI 分析评论 + for issue_num in $ISSUES; do + echo "🤖 分析 Issue #$issue_num..." + + # 获取 issue 内容 + ISSUE_BODY=$(gh issue view $issue_num --json body --jq '.body') + ISSUE_TITLE=$(gh issue view $issue_num --json title --jq '.title') + + # 添加触发评论 + gh issue comment $issue_num --body "@ai-helper 请帮我分析这个 issue" || true + + # 避免 API 限制 + sleep 2 + done + + echo "✅ 批量分析完成!" + echo "查看结果:https://github.com/${{ github.repository }}/issues" diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml new file mode 100644 index 00000000..d0747501 --- /dev/null +++ b/.github/workflows/ai-issue-helper.yml @@ -0,0 +1,50 @@ +name: AI Issue Helper + +on: + issue_comment: + types: [created] + +permissions: + issues: write + contents: read + +jobs: + ai-helper: + runs-on: ubuntu-latest + # 只在用户提到 @ai-helper 时触发 + if: contains(github.event.comment.body, '@ai-helper') + steps: + - name: AI Assistance + uses: github/issue-assessment-action@v1 + with: + assessments: + - name: help-request + prompt: | + 用户在 issue 中提到了 @ai-helper,请分析他们的问题并提供帮助。 + + 检查: + 1. 用户遇到的具体问题 + 2. 可能的解决方案 + 3. 相关文档链接 + 4. 类似的已解决 issue + + 用中文友好地回复,提供: + - 问题分析 + - 建议的解决方案(如果可以推断) + - 相关资源链接 + - 需要提供的额外信息(如果需要) + + 格式: + 👋 你好!我是 AI 助手,让我帮你分析这个问题。 + + 【问题分析】 + ... + + 【建议方案】 + ... + + 【相关资源】 + - 📚 文档:... + - 💡 示例:... + + 如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复! diff --git a/.github/workflows/ai-issue-moderator.yml b/.github/workflows/ai-issue-moderator.yml new file mode 100644 index 00000000..f5730c34 --- /dev/null +++ b/.github/workflows/ai-issue-moderator.yml @@ -0,0 +1,65 @@ +name: AI Issue Moderator + +on: + issues: + types: [opened] + issue_comment: + types: [created] + workflow_dispatch: + inputs: + issue_number: + description: 'Issue 编号(留空则检查所有打开的 issue)' + required: false + type: string + +permissions: + issues: write + contents: read + +jobs: + moderate: + runs-on: ubuntu-latest + steps: + - name: Get issue number + id: issue + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + if [ -n "${{ github.event.inputs.issue_number }}" ]; then + echo "number=${{ github.event.inputs.issue_number }}" >> $GITHUB_OUTPUT + else + echo "number=all" >> $GITHUB_OUTPUT + fi + else + echo "number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT + fi + - name: AI Content Moderation + uses: github/content-moderation-action@v1 + with: + # 检测垃圾内容 + spam-detection: true + + # 检测 AI 生成内容 + ai-generated-detection: true + + # 自定义提示 + custom-prompt: | + 分析这个 issue/评论是否包含: + 1. 垃圾信息或广告 + 2. 纯 AI 生成的无意义内容 + 3. 恶意或攻击性内容 + 4. 与项目无关的内容 + + 如果是垃圾内容,返回 "SPAM" + 如果是正常内容,返回 "OK" + + # 垃圾内容处理 + on-spam: + labels: + - "spam" + minimize: true # 隐藏内容 + comment: | + 🤖 这个 issue 被 AI 检测为可能的垃圾内容,已自动隐藏。 + 如果这是误判,请联系维护者。 + + 🤖 This issue was detected as potential spam by AI and has been hidden. + If this is a false positive, please contact the maintainers. diff --git a/.github/workflows/batch-label-issues.yml b/.github/workflows/batch-label-issues.yml new file mode 100644 index 00000000..c0c13f0c --- /dev/null +++ b/.github/workflows/batch-label-issues.yml @@ -0,0 +1,162 @@ +name: Batch Label Issues + +on: + workflow_dispatch: + inputs: + mode: + description: '标签模式' + required: true + type: choice + options: + - 'recent' # 最近 20 个 issue + - 'open' # 所有打开的 issue + - 'unlabeled' # 只处理没有标签的 issue + - 'all' # 所有 issue(慎用) + default: 'recent' + + skip_labeled: + description: '跳过已有标签的 issue' + required: false + type: boolean + default: true + +permissions: + issues: write + contents: read + +jobs: + batch-label: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + + - name: Batch Label Issues + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + MODE="${{ github.event.inputs.mode }}" + SKIP_LABELED="${{ github.event.inputs.skip_labeled }}" + + echo "📊 开始批量打标签..." + echo "模式: $MODE" + echo "跳过已标签: $SKIP_LABELED" + + # 获取 issue 列表 + if [ "$MODE" = "recent" ]; then + echo "📋 获取最近 20 个 issue..." + ISSUES=$(gh issue list --limit 20 --json number,labels,title,body --jq '.[] | {number, labels: [.labels[].name], title, body}') + elif [ "$MODE" = "open" ]; then + echo "📋 获取所有打开的 issue..." + ISSUES=$(gh issue list --state open --json number,labels,title,body --jq '.[] | {number, labels: [.labels[].name], title, body}') + elif [ "$MODE" = "unlabeled" ]; then + echo "📋 获取没有标签的 issue..." + ISSUES=$(gh issue list --state all --json number,labels,title,body --jq '.[] | select(.labels | length == 0) | {number, labels: [.labels[].name], title, body}') + else + echo "📋 获取所有 issue(限制 100 个)..." + ISSUES=$(gh issue list --state all --limit 100 --json number,labels,title,body --jq '.[] | {number, labels: [.labels[].name], title, body}') + fi + + # 临时文件 + echo "$ISSUES" > /tmp/issues.json + + # 处理每个 issue + cat /tmp/issues.json | jq -c '.' | while read -r issue; do + ISSUE_NUM=$(echo "$issue" | jq -r '.number') + EXISTING_LABELS=$(echo "$issue" | jq -r '.labels | join(",")') + TITLE=$(echo "$issue" | jq -r '.title') + BODY=$(echo "$issue" | jq -r '.body') + + echo "" + echo "🔍 处理 Issue #$ISSUE_NUM: $TITLE" + echo " 现有标签: $EXISTING_LABELS" + + # 跳过已有标签的 issue + if [ "$SKIP_LABELED" = "true" ] && [ ! -z "$EXISTING_LABELS" ]; then + echo " ⏭️ 跳过(已有标签)" + continue + fi + + # 分析内容并打标签 + LABELS_TO_ADD="" + + # 检测 bug + if echo "$TITLE $BODY" | grep -iE "(bug|错误|崩溃|crash|error|exception|问题|fix)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD bug" + echo " 🐛 检测到: bug" + fi + + # 检测 feature request + if echo "$TITLE $BODY" | grep -iE "(feature|功能|enhancement|improve|优化|建议|新增|添加|add)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD enhancement" + echo " ✨ 检测到: enhancement" + fi + + # 检测 question + if echo "$TITLE $BODY" | grep -iE "(question|疑问|how to|如何|怎么|为什么|why|咨询|\?|?)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD question" + echo " ❓ 检测到: question" + fi + + # 检测 documentation + if echo "$TITLE $BODY" | grep -iE "(doc|文档|readme|guide|tutorial|教程|说明)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD documentation" + echo " 📖 检测到: documentation" + fi + + # 检测 performance + if echo "$TITLE $BODY" | grep -iE "(performance|性能|slow|慢|lag|卡顿|optimize|优化)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD performance" + echo " ⚡ 检测到: performance" + fi + + # 检测 core + if echo "$TITLE $BODY" | grep -iE "(@esengine/ecs-framework|packages/core|core package|核心包)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD core" + echo " 🎯 检测到: core" + fi + + # 检测 editor + if echo "$TITLE $BODY" | grep -iE "(editor|编辑器|tauri)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD editor" + echo " 🎨 检测到: editor" + fi + + # 检测 network + if echo "$TITLE $BODY" | grep -iE "(network|网络|multiplayer|多人|同步)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD network" + echo " 🌐 检测到: network" + fi + + # 检测 help wanted + if echo "$TITLE $BODY" | grep -iE "(help wanted|需要帮助|求助)" > /dev/null; then + LABELS_TO_ADD="$LABELS_TO_ADD help wanted" + echo " 🆘 检测到: help wanted" + fi + + # 添加标签 + if [ ! -z "$LABELS_TO_ADD" ]; then + echo " ✅ 添加标签: $LABELS_TO_ADD" + for label in $LABELS_TO_ADD; do + gh issue edit $ISSUE_NUM --add-label "$label" 2>&1 | grep -v "already exists" || true + done + echo " 💬 添加说明评论..." + gh issue comment $ISSUE_NUM --body "🤖 自动标签系统检测到此 issue 并添加了相关标签。如有误判,请告知维护者。 + +🤖 Auto-labeling system detected and labeled this issue. Please let maintainers know if this is incorrect." || true + else + echo " ℹ️ 未检测到明确类型" + fi + + # 避免 API 限制 + sleep 1 + done + + echo "" + echo "✅ 批量标签完成!" + echo "查看结果: https://github.com/${{ github.repository }}/issues" From e7623431423850db864315127e7a28d6fcd0829b Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:26:07 +0800 Subject: [PATCH 02/11] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=20AI=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=20workflow=20=E7=9A=84=20YAML=20=E8=AF=AD?= =?UTF-8?q?=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 91 +++++++++++++++++------- .github/workflows/ai-issue-moderator.yml | 78 +++++++++----------- .github/workflows/batch-label-issues.yml | 4 +- 3 files changed, 100 insertions(+), 73 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index d0747501..56d29f43 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -14,37 +14,76 @@ jobs: # 只在用户提到 @ai-helper 时触发 if: contains(github.event.comment.body, '@ai-helper') steps: - - name: AI Assistance - uses: github/issue-assessment-action@v1 + - name: Get Issue Details + id: issue + uses: actions/github-script@v7 with: - assessments: - - name: help-request - prompt: | - 用户在 issue 中提到了 @ai-helper,请分析他们的问题并提供帮助。 + script: | + const issue = await github.rest.issues.get({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number + }); + return { + title: issue.data.title, + body: issue.data.body, + number: issue.data.number + }; - 检查: - 1. 用户遇到的具体问题 - 2. 可能的解决方案 - 3. 相关文档链接 - 4. 类似的已解决 issue + - name: AI Analysis + uses: actions/ai-inference@v1 + id: ai + with: + model: 'gpt-4o-mini' + system-prompt: | + 你是 ECS Framework 项目的 AI 助手。 + 项目信息: + - 这是一个高性能 TypeScript ECS (Entity-Component-System) 框架 + - 支持 Cocos Creator、Laya 引擎和 Web 平台 + - 文档地址:https://esengine.github.io/ecs-framework/ + - AI 文档:https://deepwiki.com/esengine/ecs-framework - 用中文友好地回复,提供: - - 问题分析 - - 建议的解决方案(如果可以推断) - - 相关资源链接 - - 需要提供的额外信息(如果需要) + 请用中文友好地回复用户的问题。 + prompt: | + 用户在 Issue #${{ github.event.issue.number }} 中请求帮助。 - 格式: - 👋 你好!我是 AI 助手,让我帮你分析这个问题。 + Issue 标题:${{ steps.issue.outputs.result.title }} - 【问题分析】 - ... + Issue 内容: + ${{ steps.issue.outputs.result.body }} - 【建议方案】 - ... + 用户评论: + ${{ github.event.comment.body }} - 【相关资源】 - - 📚 文档:... - - 💡 示例:... + 请分析用户的问题并提供帮助: + 1. 问题分析 + 2. 可能的解决方案 + 3. 相关文档链接 + 4. 需要补充的信息(如果有) - 如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复! + 用以下格式回复: + + 👋 你好!我是 AI 助手,让我帮你分析这个问题。 + + **问题分析** + [分析内容] + + **建议方案** + [解决方案] + + **相关资源** + - 📚 [文档链接] + - 💡 [示例链接] + + 如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复! + + - name: Post AI Response + uses: actions/github-script@v7 + with: + script: | + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `${{ steps.ai.outputs.response }}` + }); diff --git a/.github/workflows/ai-issue-moderator.yml b/.github/workflows/ai-issue-moderator.yml index f5730c34..9be6cb69 100644 --- a/.github/workflows/ai-issue-moderator.yml +++ b/.github/workflows/ai-issue-moderator.yml @@ -5,12 +5,6 @@ on: types: [opened] issue_comment: types: [created] - workflow_dispatch: - inputs: - issue_number: - description: 'Issue 编号(留空则检查所有打开的 issue)' - required: false - type: string permissions: issues: write @@ -20,46 +14,42 @@ jobs: moderate: runs-on: ubuntu-latest steps: - - name: Get issue number - id: issue - run: | - if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then - if [ -n "${{ github.event.inputs.issue_number }}" ]; then - echo "number=${{ github.event.inputs.issue_number }}" >> $GITHUB_OUTPUT - else - echo "number=all" >> $GITHUB_OUTPUT - fi - else - echo "number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT - fi - - name: AI Content Moderation - uses: github/content-moderation-action@v1 + - name: Check Content + uses: actions/ai-inference@v1 + id: check with: - # 检测垃圾内容 - spam-detection: true - - # 检测 AI 生成内容 - ai-generated-detection: true - - # 自定义提示 - custom-prompt: | - 分析这个 issue/评论是否包含: + model: 'gpt-4o-mini' + system-prompt: | + 你是一个内容审查助手。 + 检查内容是否包含: 1. 垃圾信息或广告 - 2. 纯 AI 生成的无意义内容 - 3. 恶意或攻击性内容 - 4. 与项目无关的内容 + 2. 恶意或攻击性内容 + 3. 与项目完全无关的内容 - 如果是垃圾内容,返回 "SPAM" - 如果是正常内容,返回 "OK" + 只返回 "SPAM" 或 "OK",不要其他内容。 + prompt: | + 标题:${{ github.event.issue.title || github.event.comment.body }} - # 垃圾内容处理 - on-spam: - labels: - - "spam" - minimize: true # 隐藏内容 - comment: | - 🤖 这个 issue 被 AI 检测为可能的垃圾内容,已自动隐藏。 - 如果这是误判,请联系维护者。 + 内容: + ${{ github.event.issue.body || github.event.comment.body }} - 🤖 This issue was detected as potential spam by AI and has been hidden. - If this is a false positive, please contact the maintainers. + - name: Mark as Spam + if: contains(steps.check.outputs.response, 'SPAM') + uses: actions/github-script@v7 + with: + script: | + // 添加 spam 标签 + github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + labels: ['spam'] + }); + + // 添加评论 + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: '🤖 这个内容被 AI 检测为可能的垃圾内容。如果这是误判,请联系维护者。\n\n🤖 This content was detected as potential spam by AI. If this is a false positive, please contact the maintainers.' + }); diff --git a/.github/workflows/batch-label-issues.yml b/.github/workflows/batch-label-issues.yml index c0c13f0c..24a25058 100644 --- a/.github/workflows/batch-label-issues.yml +++ b/.github/workflows/batch-label-issues.yml @@ -146,9 +146,7 @@ jobs: gh issue edit $ISSUE_NUM --add-label "$label" 2>&1 | grep -v "already exists" || true done echo " 💬 添加说明评论..." - gh issue comment $ISSUE_NUM --body "🤖 自动标签系统检测到此 issue 并添加了相关标签。如有误判,请告知维护者。 - -🤖 Auto-labeling system detected and labeled this issue. Please let maintainers know if this is incorrect." || true + gh issue comment $ISSUE_NUM --body $'🤖 自动标签系统检测到此 issue 并添加了相关标签。如有误判,请告知维护者。\n\n🤖 Auto-labeling system detected and labeled this issue. Please let maintainers know if this is incorrect.' || true else echo " ℹ️ 未检测到明确类型" fi From 330d9a6fdbf390f0ad73fcd8f727fbe0d97b3651 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:33:12 +0800 Subject: [PATCH 03/11] =?UTF-8?q?fix(ci):=20=E4=B8=BA=20AI=20workflow=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20models=20=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 1 + .github/workflows/ai-issue-moderator.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index 56d29f43..ba3ea182 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -7,6 +7,7 @@ on: permissions: issues: write contents: read + models: read jobs: ai-helper: diff --git a/.github/workflows/ai-issue-moderator.yml b/.github/workflows/ai-issue-moderator.yml index 9be6cb69..a50bf6f5 100644 --- a/.github/workflows/ai-issue-moderator.yml +++ b/.github/workflows/ai-issue-moderator.yml @@ -9,6 +9,7 @@ on: permissions: issues: write contents: read + models: read jobs: moderate: From ab04ad30f1734ec7c5159fb355a652201ef4891e Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:39:10 +0800 Subject: [PATCH 04/11] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=20AI=20Issu?= =?UTF-8?q?e=20Helper=20=E7=9A=84=E6=95=B0=E6=8D=AE=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index ba3ea182..9fcfc268 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -48,10 +48,10 @@ jobs: prompt: | 用户在 Issue #${{ github.event.issue.number }} 中请求帮助。 - Issue 标题:${{ steps.issue.outputs.result.title }} + Issue 标题:${{ fromJSON(steps.issue.outputs.result).title }} Issue 内容: - ${{ steps.issue.outputs.result.body }} + ${{ fromJSON(steps.issue.outputs.result).body }} 用户评论: ${{ github.event.comment.body }} From b5b64f8c4100eca03ca95bb2f5b70542211d4002 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:43:40 +0800 Subject: [PATCH 05/11] =?UTF-8?q?feat(ci):=20=E4=B8=BA=20AI=20Issue=20Help?= =?UTF-8?q?er=20=E6=B7=BB=E5=8A=A0=E4=BB=A3=E7=A0=81=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index 9fcfc268..70e89e9f 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -15,6 +15,9 @@ jobs: # 只在用户提到 @ai-helper 时触发 if: contains(github.event.comment.body, '@ai-helper') steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Get Issue Details id: issue uses: actions/github-script@v7 @@ -36,14 +39,20 @@ jobs: id: ai with: model: 'gpt-4o-mini' + mcp: github system-prompt: | 你是 ECS Framework 项目的 AI 助手。 + 项目信息: - 这是一个高性能 TypeScript ECS (Entity-Component-System) 框架 - 支持 Cocos Creator、Laya 引擎和 Web 平台 + - 主要代码在 packages/core/src 目录 - 文档地址:https://esengine.github.io/ecs-framework/ - AI 文档:https://deepwiki.com/esengine/ecs-framework + 你可以使用 GitHub 工具搜索代码、查看文件内容来准确回答问题。 + 在回答之前,先搜索相关代码和文档,确保答案准确。 + 请用中文友好地回复用户的问题。 prompt: | 用户在 Issue #${{ github.event.issue.number }} 中请求帮助。 @@ -56,11 +65,11 @@ jobs: 用户评论: ${{ github.event.comment.body }} - 请分析用户的问题并提供帮助: - 1. 问题分析 - 2. 可能的解决方案 - 3. 相关文档链接 - 4. 需要补充的信息(如果有) + 请按以下步骤回答: + 1. 使用 GitHub 工具搜索项目中的相关代码和文件 + 2. 分析用户的问题 + 3. 基于实际代码提供准确的解决方案 + 4. 提供相关文档链接和代码示例 用以下格式回复: @@ -70,7 +79,10 @@ jobs: [分析内容] **建议方案** - [解决方案] + [基于项目实际代码的解决方案] + + **相关代码** + [引用项目中的相关代码片段] **相关资源** - 📚 [文档链接] From 77701f214c9b7643b65ebcd6fa66a6a425c75fc2 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:51:23 +0800 Subject: [PATCH 06/11] =?UTF-8?q?fix(ci):=20AI=20Issue=20Helper=20?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E6=9C=BA=E5=99=A8=E4=BA=BA=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 79 ++++++++++++--------------- 1 file changed, 35 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index 70e89e9f..166c27f2 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -12,27 +12,52 @@ permissions: jobs: ai-helper: runs-on: ubuntu-latest - # 只在用户提到 @ai-helper 时触发 - if: contains(github.event.comment.body, '@ai-helper') + # 只在真实用户提到 @ai-helper 时触发,忽略机器人评论 + if: | + contains(github.event.comment.body, '@ai-helper') && + github.event.comment.user.type != 'Bot' steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Get Issue Details - id: issue + - name: Create Prompt File uses: actions/github-script@v7 with: script: | + const fs = require('fs'); const issue = await github.rest.issues.get({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number }); - return { - title: issue.data.title, - body: issue.data.body, - number: issue.data.number - }; + + const lines = []; + lines.push('用户在 Issue #' + context.issue.number + ' 中请求帮助。\n'); + lines.push('Issue 标题:'); + lines.push(issue.data.title || '(无标题)'); + lines.push('\nIssue 内容:'); + lines.push(issue.data.body || '(无内容)'); + lines.push('\n用户评论:'); + lines.push(context.payload.comment.body); + lines.push('\n请按以下步骤回答:'); + lines.push('1. 使用 GitHub 工具搜索项目中的相关代码和文件'); + lines.push('2. 分析用户的问题'); + lines.push('3. 基于实际代码提供准确的解决方案'); + lines.push('4. 提供相关文档链接和代码示例'); + lines.push('\n用以下格式回复:'); + lines.push('\n你好!我是 AI 助手,让我帮你分析这个问题。'); + lines.push('\n**问题分析**'); + lines.push('[分析内容]'); + lines.push('\n**建议方案**'); + lines.push('[基于项目实际代码的解决方案]'); + lines.push('\n**相关代码**'); + lines.push('[引用项目中的相关代码片段]'); + lines.push('\n**相关资源**'); + lines.push('- 文档链接'); + lines.push('- 示例链接'); + lines.push('\n如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复!'); + + fs.writeFileSync('prompt.txt', lines.join('\n')); - name: AI Analysis uses: actions/ai-inference@v1 @@ -54,41 +79,7 @@ jobs: 在回答之前,先搜索相关代码和文档,确保答案准确。 请用中文友好地回复用户的问题。 - prompt: | - 用户在 Issue #${{ github.event.issue.number }} 中请求帮助。 - - Issue 标题:${{ fromJSON(steps.issue.outputs.result).title }} - - Issue 内容: - ${{ fromJSON(steps.issue.outputs.result).body }} - - 用户评论: - ${{ github.event.comment.body }} - - 请按以下步骤回答: - 1. 使用 GitHub 工具搜索项目中的相关代码和文件 - 2. 分析用户的问题 - 3. 基于实际代码提供准确的解决方案 - 4. 提供相关文档链接和代码示例 - - 用以下格式回复: - - 👋 你好!我是 AI 助手,让我帮你分析这个问题。 - - **问题分析** - [分析内容] - - **建议方案** - [基于项目实际代码的解决方案] - - **相关代码** - [引用项目中的相关代码片段] - - **相关资源** - - 📚 [文档链接] - - 💡 [示例链接] - - 如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复! + prompt: prompt.txt - name: Post AI Response uses: actions/github-script@v7 From 367d97e9bbc250fcdea0cc694b47face38c222cb Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:55:47 +0800 Subject: [PATCH 07/11] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=20AI=20Issu?= =?UTF-8?q?e=20Helper=20=E7=9A=84=20prompt=20=E6=96=87=E4=BB=B6=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 76 +++++++++++++++++---------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index 166c27f2..a72fe138 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -20,44 +20,62 @@ jobs: - name: Checkout Repository uses: actions/checkout@v4 - - name: Create Prompt File + - name: Get Issue Details + id: issue uses: actions/github-script@v7 with: script: | - const fs = require('fs'); const issue = await github.rest.issues.get({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number }); - const lines = []; - lines.push('用户在 Issue #' + context.issue.number + ' 中请求帮助。\n'); - lines.push('Issue 标题:'); - lines.push(issue.data.title || '(无标题)'); - lines.push('\nIssue 内容:'); - lines.push(issue.data.body || '(无内容)'); - lines.push('\n用户评论:'); - lines.push(context.payload.comment.body); - lines.push('\n请按以下步骤回答:'); - lines.push('1. 使用 GitHub 工具搜索项目中的相关代码和文件'); - lines.push('2. 分析用户的问题'); - lines.push('3. 基于实际代码提供准确的解决方案'); - lines.push('4. 提供相关文档链接和代码示例'); - lines.push('\n用以下格式回复:'); - lines.push('\n你好!我是 AI 助手,让我帮你分析这个问题。'); - lines.push('\n**问题分析**'); - lines.push('[分析内容]'); - lines.push('\n**建议方案**'); - lines.push('[基于项目实际代码的解决方案]'); - lines.push('\n**相关代码**'); - lines.push('[引用项目中的相关代码片段]'); - lines.push('\n**相关资源**'); - lines.push('- 文档链接'); - lines.push('- 示例链接'); - lines.push('\n如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复!'); + core.exportVariable('ISSUE_TITLE', issue.data.title || ''); + core.exportVariable('ISSUE_BODY', issue.data.body || ''); + core.exportVariable('COMMENT_BODY', context.payload.comment.body || ''); + core.exportVariable('ISSUE_NUMBER', context.issue.number); - fs.writeFileSync('prompt.txt', lines.join('\n')); + - name: Create Prompt + id: prompt + run: | + cat > prompt.txt << 'PROMPT_EOF' + 用户在 Issue #${{ env.ISSUE_NUMBER }} 中请求帮助。 + + Issue 标题: + ${{ env.ISSUE_TITLE }} + + Issue 内容: + ${{ env.ISSUE_BODY }} + + 用户评论: + ${{ env.COMMENT_BODY }} + + 请按以下步骤回答: + 1. 使用 GitHub 工具搜索项目中的相关代码和文件 + 2. 分析用户的问题 + 3. 基于实际代码提供准确的解决方案 + 4. 提供相关文档链接和代码示例 + + 用以下格式回复: + + 你好!我是 AI 助手,让我帮你分析这个问题。 + + **问题分析** + [分析内容] + + **建议方案** + [基于项目实际代码的解决方案] + + **相关代码** + [引用项目中的相关代码片段] + + **相关资源** + - 文档链接 + - 示例链接 + + 如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复! + PROMPT_EOF - name: AI Analysis uses: actions/ai-inference@v1 @@ -79,7 +97,7 @@ jobs: 在回答之前,先搜索相关代码和文档,确保答案准确。 请用中文友好地回复用户的问题。 - prompt: prompt.txt + prompt-file: prompt.txt - name: Post AI Response uses: actions/github-script@v7 From f93de879406b47e0bdb82bbb7d8d4ef3c696047a Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 00:59:04 +0800 Subject: [PATCH 08/11] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=20AI=20?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E5=8C=85=E5=90=AB=E4=BB=A3=E7=A0=81=E6=97=B6?= =?UTF-8?q?=E7=9A=84=20JavaScript=20=E8=AF=AD=E6=B3=95=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index a72fe138..fd45ab38 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -99,13 +99,20 @@ jobs: 请用中文友好地回复用户的问题。 prompt-file: prompt.txt + - name: Save AI Response + run: | + echo "${{ steps.ai.outputs.response }}" > ai_response.txt + - name: Post AI Response uses: actions/github-script@v7 with: script: | - github.rest.issues.createComment({ + const fs = require('fs'); + const response = fs.readFileSync('ai_response.txt', 'utf8'); + + await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, - body: `${{ steps.ai.outputs.response }}` + body: response }); From 130f466026af6c73eef8c96b7788cc0a93debc18 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 01:01:18 +0800 Subject: [PATCH 09/11] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8D=20AI=20Issu?= =?UTF-8?q?e=20Helper=20=E7=9A=84=20MCP=20=E9=85=8D=E7=BD=AE=E5=92=8C?= =?UTF-8?q?=E5=93=8D=E5=BA=94=E4=BC=A0=E9=80=92=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index fd45ab38..5e8ec939 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -82,7 +82,7 @@ jobs: id: ai with: model: 'gpt-4o-mini' - mcp: github + enable-github-mcp: true system-prompt: | 你是 ECS Framework 项目的 AI 助手。 @@ -99,20 +99,15 @@ jobs: 请用中文友好地回复用户的问题。 prompt-file: prompt.txt - - name: Save AI Response - run: | - echo "${{ steps.ai.outputs.response }}" > ai_response.txt - - name: Post AI Response + env: + AI_RESPONSE: ${{ steps.ai.outputs.response }} uses: actions/github-script@v7 with: script: | - const fs = require('fs'); - const response = fs.readFileSync('ai_response.txt', 'utf8'); - await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, - body: response + body: process.env.AI_RESPONSE }); From 0daa92cfb791bf70d06d12a906a14907901aab5e Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 01:03:55 +0800 Subject: [PATCH 10/11] =?UTF-8?q?fix(ci):=20=E4=BC=98=E5=8C=96=20AI=20Issu?= =?UTF-8?q?e=20Helper=20=E9=81=BF=E5=85=8D=20token=20=E8=B6=85=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 66 ++++++++------------------- 1 file changed, 19 insertions(+), 47 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index 5e8ec939..8675e7d5 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -31,50 +31,31 @@ jobs: issue_number: context.issue.number }); - core.exportVariable('ISSUE_TITLE', issue.data.title || ''); - core.exportVariable('ISSUE_BODY', issue.data.body || ''); - core.exportVariable('COMMENT_BODY', context.payload.comment.body || ''); + // 限制长度,避免超过 token 限制 + const maxLength = 1000; + const truncate = (str, max) => { + if (!str) return ''; + return str.length > max ? str.substring(0, max) + '...[内容过长已截断]' : str; + }; + + core.exportVariable('ISSUE_TITLE', truncate(issue.data.title || '', 200)); + core.exportVariable('ISSUE_BODY', truncate(issue.data.body || '', maxLength)); + core.exportVariable('COMMENT_BODY', truncate(context.payload.comment.body || '', 500)); core.exportVariable('ISSUE_NUMBER', context.issue.number); - name: Create Prompt id: prompt run: | cat > prompt.txt << 'PROMPT_EOF' - 用户在 Issue #${{ env.ISSUE_NUMBER }} 中请求帮助。 + Issue #${{ env.ISSUE_NUMBER }} - Issue 标题: - ${{ env.ISSUE_TITLE }} + 标题: ${{ env.ISSUE_TITLE }} - Issue 内容: - ${{ env.ISSUE_BODY }} + 内容: ${{ env.ISSUE_BODY }} - 用户评论: - ${{ env.COMMENT_BODY }} + 评论: ${{ env.COMMENT_BODY }} - 请按以下步骤回答: - 1. 使用 GitHub 工具搜索项目中的相关代码和文件 - 2. 分析用户的问题 - 3. 基于实际代码提供准确的解决方案 - 4. 提供相关文档链接和代码示例 - - 用以下格式回复: - - 你好!我是 AI 助手,让我帮你分析这个问题。 - - **问题分析** - [分析内容] - - **建议方案** - [基于项目实际代码的解决方案] - - **相关代码** - [引用项目中的相关代码片段] - - **相关资源** - - 文档链接 - - 示例链接 - - 如果我的建议没有解决问题,请提供更多信息,维护者会尽快回复! + 请搜索项目代码并提供解决方案。 PROMPT_EOF - name: AI Analysis @@ -83,20 +64,11 @@ jobs: with: model: 'gpt-4o-mini' enable-github-mcp: true + max-tokens: 1000 system-prompt: | - 你是 ECS Framework 项目的 AI 助手。 - - 项目信息: - - 这是一个高性能 TypeScript ECS (Entity-Component-System) 框架 - - 支持 Cocos Creator、Laya 引擎和 Web 平台 - - 主要代码在 packages/core/src 目录 - - 文档地址:https://esengine.github.io/ecs-framework/ - - AI 文档:https://deepwiki.com/esengine/ecs-framework - - 你可以使用 GitHub 工具搜索代码、查看文件内容来准确回答问题。 - 在回答之前,先搜索相关代码和文档,确保答案准确。 - - 请用中文友好地回复用户的问题。 + 你是 ECS Framework (TypeScript ECS 框架) 的 AI 助手。 + 主要代码在 packages/core/src。 + 搜索相关代码后,用中文简洁回答问题,包含问题分析、解决方案和代码引用。 prompt-file: prompt.txt - name: Post AI Response From ec5de979738c55d2e9b28db9e36876e79930c2a4 Mon Sep 17 00:00:00 2001 From: YHH <359807859@qq.com> Date: Sun, 19 Oct 2025 01:08:11 +0800 Subject: [PATCH 11/11] =?UTF-8?q?fix(ci):=20=E6=8D=A2=E7=94=A8=20gpt-4o=20?= =?UTF-8?q?=E6=A8=A1=E5=9E=8B=E8=A7=A3=E5=86=B3=20token=20=E8=B6=85?= =?UTF-8?q?=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ai-issue-helper.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ai-issue-helper.yml b/.github/workflows/ai-issue-helper.yml index 8675e7d5..86bc95e4 100644 --- a/.github/workflows/ai-issue-helper.yml +++ b/.github/workflows/ai-issue-helper.yml @@ -62,9 +62,9 @@ jobs: uses: actions/ai-inference@v1 id: ai with: - model: 'gpt-4o-mini' + model: 'gpt-4o' enable-github-mcp: true - max-tokens: 1000 + max-tokens: 1500 system-prompt: | 你是 ECS Framework (TypeScript ECS 框架) 的 AI 助手。 主要代码在 packages/core/src。