(commits)
| 54 | |
| 55 | // 增强版 Gemini AI 总结功能 |
| 56 | async function summarizeWithGemini(commits) { |
| 57 | console.log('\n🤖 === Gemini AI 处理开始 ==='); |
| 58 | |
| 59 | if (!GEMINI_API_KEY) { |
| 60 | console.warn('⚠️ 未配置 GEMINI_API_KEY,使用基础总结模式'); |
| 61 | console.warn(' 请在 GitHub Settings → Secrets → Actions 中添加 GEMINI_API_KEY'); |
| 62 | return null; |
| 63 | } |
| 64 | |
| 65 | try { |
| 66 | // 准备提交记录文本 |
| 67 | const commitsText = commits.map(c => |
| 68 | `- [${c.author}] ${c.message}` |
| 69 | ).join('\n'); |
| 70 | |
| 71 | // 获取实际日期和版本号 |
| 72 | const currentDate = TARGET_DATE || formatDateInTimeZone(new Date(), LOCAL_TZ); |
| 73 | const version = `0.${new Date().getMonth() + 1}.${new Date().getDate()}`; // 动态生成版本号 |
| 74 | |
| 75 | // 使用更新的提示词生成函数 |
| 76 | const { generatePrompt } = require('./update-template'); |
| 77 | const promptTemplate = generatePrompt(currentDate, version); |
| 78 | const fullPrompt = promptTemplate + commitsText; |
| 79 | console.log('📏 Prompt 长度:', fullPrompt.length, '字符'); |
| 80 | |
| 81 | // 使用增强的 API 调用 |
| 82 | const result = await callGeminiAPI(GEMINI_API_KEY, fullPrompt); |
| 83 | |
| 84 | if (result.success) { |
| 85 | console.log('✅ === Gemini AI 处理成功 ===\n'); |
| 86 | return result.content; |
| 87 | } else { |
| 88 | console.error('❌ === Gemini AI 处理失败 ==='); |
| 89 | console.error(' 错误信息:', result.error); |
| 90 | |
| 91 | // 尝试诊断常见问题 |
| 92 | if (result.error.includes('API key not valid')) { |
| 93 | console.error(' 💡 解决方案: 请检查 GEMINI_API_KEY 是否正确'); |
| 94 | } else if (result.error.includes('quota')) { |
| 95 | console.error(' 💡 解决方案: API 配额已用完,请检查 Google Cloud Console'); |
| 96 | } else if (result.error.includes('timeout')) { |
| 97 | console.error(' 💡 解决方案: 网络超时,可能需要配置代理或稍后重试'); |
| 98 | } |
| 99 | |
| 100 | return null; |
| 101 | } |
| 102 | } catch (error) { |
| 103 | console.error('❌ 意外错误:', error.message); |
| 104 | console.error(' 错误堆栈:', error.stack); |
| 105 | return null; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | // 获取指定日期的提交 |
| 110 | function getCommitsForDate(repoPath, repoName, date) { |
no test coverage detected