mirror of
https://github.com/ZhuLinsen/daily_stock_analysis
synced 2026-09-20 10:53:33 +08:00
feat: 添加自动关闭过期内容和改进 AI 审查调试
This commit is contained in:
26
.github/scripts/ai_review.py
vendored
26
.github/scripts/ai_review.py
vendored
@@ -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
|
||||
|
||||
|
||||
|
||||
2
.github/workflows/pr-review.yml
vendored
2
.github/workflows/pr-review.yml
vendored
@@ -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
|
||||
|
||||
79
.github/workflows/stale.yml
vendored
Normal file
79
.github/workflows/stale.yml
vendored
Normal file
@@ -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
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -59,4 +59,6 @@ Thumbs.db
|
||||
.coverage
|
||||
htmlcov/
|
||||
|
||||
docs/
|
||||
docs/
|
||||
|
||||
run.sh
|
||||
Reference in New Issue
Block a user