From 9fcb5a8df1233d0343810930b6a2cd2252fce3ee Mon Sep 17 00:00:00 2001 From: zhulinsen Date: Wed, 14 Jan 2026 20:40:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=85=B3=E9=97=AD=E8=BF=87=E6=9C=9F=E5=86=85=E5=AE=B9=E5=92=8C?= =?UTF-8?q?=E6=94=B9=E8=BF=9B=20AI=20=E5=AE=A1=E6=9F=A5=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/scripts/ai_review.py | 26 ++++++++++- .github/workflows/pr-review.yml | 2 + .github/workflows/stale.yml | 79 +++++++++++++++++++++++++++++++++ .gitignore | 4 +- 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/stale.yml diff --git a/.github/scripts/ai_review.py b/.github/scripts/ai_review.py index 3d907b458..e1ec3c9db 100644 --- a/.github/scripts/ai_review.py +++ b/.github/scripts/ai_review.py @@ -5,6 +5,8 @@ AI 代码审查脚本 """ import os import subprocess +import traceback + MAX_DIFF_LENGTH = 15000 @@ -77,9 +79,13 @@ def review_with_gemini(prompt): model = os.environ.get('GEMINI_MODEL_FALLBACK', 'gemini-2.5-flash') if not api_key: - print("Gemini API Key 未配置") + print("❌ Gemini API Key 未配置(检查 GitHub Secrets: GEMINI_API_KEY)") return None + # 打印部分 key 用于调试(只显示前8位) + print(f"🔑 Gemini API Key: {api_key[:8]}... (长度: {len(api_key)})") + print(f"🤖 使用模型: {model}") + try: from google import genai client = genai.Client(api_key=api_key) @@ -89,8 +95,15 @@ def review_with_gemini(prompt): ) print(f"✅ Gemini ({model}) 审查成功") return response.text + except ImportError as e: + print(f"❌ Gemini 依赖未安装: {e}") + print(" 请确保安装了 google-genai: pip install google-genai") + return None except Exception as e: print(f"❌ Gemini 审查失败: {e}") + # 打印更详细的错误信息 + import traceback + traceback.print_exc() return None @@ -101,9 +114,13 @@ def review_with_openai(prompt): model = os.environ.get('OPENAI_MODEL', 'gpt-4o-mini') if not api_key: - print("OpenAI API Key 未配置") + print("❌ OpenAI API Key 未配置(检查 GitHub Secrets: OPENAI_API_KEY)") return None + print(f"🔑 OpenAI API Key: {api_key[:8]}... (长度: {len(api_key)})") + print(f"🌐 Base URL: {base_url}") + print(f"🤖 使用模型: {model}") + try: from openai import OpenAI client = OpenAI(api_key=api_key, base_url=base_url) @@ -115,8 +132,13 @@ def review_with_openai(prompt): ) print(f"✅ OpenAI 兼容接口 ({model}) 审查成功") return response.choices[0].message.content + except ImportError as e: + print(f"❌ OpenAI 依赖未安装: {e}") + print(" 请确保安装了 openai: pip install openai") + return None except Exception as e: print(f"❌ OpenAI 兼容接口审查失败: {e}") + traceback.print_exc() return None diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 07b1c6a53..0e8933a69 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -24,6 +24,7 @@ concurrency: permissions: contents: read pull-requests: write + issues: write jobs: # ==================== 静态检查(先于 AI 审查)==================== @@ -260,6 +261,7 @@ jobs: - name: 📥 下载 AI 审查结果 uses: actions/download-artifact@v4 + if: needs.ai-review.result == 'success' continue-on-error: true with: name: ai-review-result diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml new file mode 100644 index 000000000..a52685988 --- /dev/null +++ b/.github/workflows/stale.yml @@ -0,0 +1,79 @@ +# 自动关闭过期的 Issues 和 PR +# 每天检查一次,标记长时间无响应的 issues/PRs + +name: Stale Issues & PRs + +on: + schedule: + # 每天 UTC 0:00(北京时间 8:00)检查一次 + - cron: '0 0 * * *' + # 支持手动触发 + workflow_dispatch: + +permissions: + issues: write + pull-requests: write + +jobs: + stale: + name: 🧹 清理过期 Issues/PRs + runs-on: ubuntu-latest + + steps: + - name: 🏷️ 标记并关闭过期内容 + uses: actions/stale@v9 + with: + # ===== Issue 配置 ===== + days-before-issue-stale: 2 + days-before-issue-close: 1 + stale-issue-label: 'stale' + stale-issue-message: | + 👋 这个 Issue 已经 **2 天** 没有活动了。 + + 如果问题仍然存在,请回复说明最新情况,我们会继续跟进。 + 如果问题已解决或不再需要,可以直接关闭此 Issue。 + + **如果 1 天内没有回复,此 Issue 将自动关闭。** + close-issue-message: | + 🔒 由于长时间没有活动,此 Issue 已自动关闭。 + + 如果问题仍然存在,欢迎重新打开或创建新的 Issue。 + + # ===== PR 配置 ===== + days-before-pr-stale: 21 + days-before-pr-close: 14 + stale-pr-label: 'stale' + stale-pr-message: | + 👋 这个 PR 已经 **21 天** 没有活动了。 + + 请检查是否需要: + - 解决合并冲突 + - 回复 review 意见 + - 更新代码 + + **如果 14 天内没有更新,此 PR 将自动关闭。** + close-pr-message: | + 🔒 由于长时间没有活动,此 PR 已自动关闭。 + + 如果您仍希望合入这些更改,请重新打开或创建新的 PR。 + + # ===== 排除规则 ===== + # 带有这些标签的不会被标记为 stale + exempt-issue-labels: 'pinned,security,enhancement,help wanted,good first issue' + exempt-pr-labels: 'pinned,security,work-in-progress,wip' + + # 排除草稿 PR + exempt-draft-pr: true + + # ===== 其他配置 ===== + # 每次运行最多处理的数量 + operations-per-run: 50 + + # 只处理这些状态的 + only-labels: '' + + # 移除 stale 标签(当有新活动时) + remove-stale-when-updated: true + + # 调试模式(设为 true 时只打印不实际操作) + debug-only: false diff --git a/.gitignore b/.gitignore index 92699840b..09dcb4257 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,6 @@ Thumbs.db .coverage htmlcov/ -docs/ \ No newline at end of file +docs/ + +run.sh \ No newline at end of file