|
| 1 | +## 自动分析并回复仓库 Issue ## |
| 2 | + |
| 3 | +name: Issue Response Bot |
| 4 | + |
| 5 | +on: |
| 6 | + issues: |
| 7 | + types: [opened] |
| 8 | + schedule: |
| 9 | + - cron: '0 1 * * *' # 每天国际标准时间 01:00(北京时间 09:00)运行 |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + issues: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + respond-to-new-issue: |
| 17 | + name: 回复新开的 Issue |
| 18 | + runs-on: ubuntu-latest |
| 19 | + if: github.event_name == 'issues' && github.event.action == 'opened' |
| 20 | + steps: |
| 21 | + - name: 自动回复新 Issue |
| 22 | + uses: actions/github-script@v7 |
| 23 | + with: |
| 24 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 25 | + script: | |
| 26 | + const issue = context.payload.issue; |
| 27 | + const labels = issue.labels.map(l => l.name); |
| 28 | + const issueNumber = issue.number; |
| 29 | + const author = issue.user.login; |
| 30 | +
|
| 31 | + const bugComment = [ |
| 32 | + `👋 @${author} 感谢您提交 Bug 反馈!`, |
| 33 | + '', |
| 34 | + '我们已收到您的问题报告,将尽快安排排查。', |
| 35 | + '', |
| 36 | + '在处理之前,请确认您的 Issue 已提供以下信息(否则我们可能无法重现问题):', |
| 37 | + '', |
| 38 | + '- ✅ **NotionNext 版本号**(例如:4.9.4.2)', |
| 39 | + '- ✅ **使用的主题**(例如:hexo / heo / next)', |
| 40 | + '- ✅ **部署方案**(例如:Vercel / Cloudflare Pages / 自托管)', |
| 41 | + '- ✅ **复现步骤**(清晰的步骤描述)', |
| 42 | + '- ✅ **期望结果与实际结果**', |
| 43 | + '', |
| 44 | + '如果以上信息不完整,请补充后我们会继续跟进。感谢您对 NotionNext 的贡献! 🙏', |
| 45 | + ].join('\n'); |
| 46 | +
|
| 47 | + const enhancementComment = [ |
| 48 | + `👋 @${author} 感谢您提交新特性建议!`, |
| 49 | + '', |
| 50 | + '您的建议已被收录,我们将在评估可行性后决定是否纳入后续版本。', |
| 51 | + '', |
| 52 | + '如果您有能力参与实现,欢迎提交 PR!具体开发规范请参阅 [贡献指南](https://github.com/tangly1024/NotionNext/blob/main/README.md)。', |
| 53 | + '', |
| 54 | + '感谢您对 NotionNext 的支持! 🙏', |
| 55 | + ].join('\n'); |
| 56 | +
|
| 57 | + const deploymentComment = [ |
| 58 | + `👋 @${author} 感谢您反馈部署问题!`, |
| 59 | + '', |
| 60 | + '以下是常见部署问题的排查建议,请先自查:', |
| 61 | + '', |
| 62 | + '1. 📝 确认 `NOTION_PAGE_ID` 已正确配置并且 Notion 页面已公开分享。', |
| 63 | + '2. 🔑 确认所有必要的环境变量(如 `NEXT_PUBLIC_*`)已在部署平台正确设置。', |
| 64 | + '3. 📦 确认使用的 Node.js 版本为 20.x(兼容 20/22/24),依赖安装命令为 `yarn`。', |
| 65 | + '4. 📖 参阅官方文档:[部署指南](https://github.com/tangly1024/NotionNext#部署)', |
| 66 | + '', |
| 67 | + '如果以上步骤均已确认,请补充更详细的错误日志,我们将继续协助排查。感谢您的耐心! 🙏', |
| 68 | + ].join('\n'); |
| 69 | +
|
| 70 | + const helpComment = [ |
| 71 | + `👋 @${author} 您好,感谢您使用 NotionNext!`, |
| 72 | + '', |
| 73 | + '请详细描述您遇到的问题以及期望的结果,以便社区成员更好地帮助您。', |
| 74 | + '', |
| 75 | + '同时也欢迎加入我们的社区交流群获取更快速的帮助:[Telegram 群组](https://t.me/Notionso)', |
| 76 | + '', |
| 77 | + '感谢您的使用! 🙏', |
| 78 | + ].join('\n'); |
| 79 | +
|
| 80 | + const defaultComment = [ |
| 81 | + `👋 @${author} 感谢您提交 Issue!`, |
| 82 | + '', |
| 83 | + '我们已收到您的反馈,将尽快处理。如有需要,我们会与您进一步沟通。', |
| 84 | + '', |
| 85 | + '欢迎加入我们的社区:[Telegram 群组](https://t.me/Notionso)', |
| 86 | + '', |
| 87 | + '感谢您对 NotionNext 的支持! 🙏', |
| 88 | + ].join('\n'); |
| 89 | +
|
| 90 | + let comment = defaultComment; |
| 91 | + if (labels.includes('bug')) { |
| 92 | + comment = bugComment; |
| 93 | + } else if (labels.includes('enhancement')) { |
| 94 | + comment = enhancementComment; |
| 95 | + } else if (labels.includes('deployment')) { |
| 96 | + comment = deploymentComment; |
| 97 | + } else if (labels.includes('help wanted')) { |
| 98 | + comment = helpComment; |
| 99 | + } |
| 100 | +
|
| 101 | + await github.rest.issues.createComment({ |
| 102 | + owner: context.repo.owner, |
| 103 | + repo: context.repo.repo, |
| 104 | + issue_number: issueNumber, |
| 105 | + body: comment, |
| 106 | + }); |
| 107 | +
|
| 108 | + daily-triage: |
| 109 | + name: 每日 Issue 处理 |
| 110 | + runs-on: ubuntu-latest |
| 111 | + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' |
| 112 | + steps: |
| 113 | + - name: 处理未回复的 Issue |
| 114 | + uses: actions/github-script@v7 |
| 115 | + with: |
| 116 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 117 | + script: | |
| 118 | + const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(); |
| 119 | +
|
| 120 | + const { data: issues } = await github.rest.issues.listForRepo({ |
| 121 | + owner: context.repo.owner, |
| 122 | + repo: context.repo.repo, |
| 123 | + state: 'open', |
| 124 | + since: oneDayAgo, |
| 125 | + per_page: 100, |
| 126 | + }); |
| 127 | +
|
| 128 | + const buildComment = (author, labels) => { |
| 129 | + const bugComment = [ |
| 130 | + `👋 @${author} 感谢您提交 Bug 反馈!`, |
| 131 | + '', |
| 132 | + '我们已收到您的问题报告,将尽快安排排查。', |
| 133 | + '', |
| 134 | + '在处理之前,请确认您的 Issue 已提供以下信息(否则我们可能无法重现问题):', |
| 135 | + '', |
| 136 | + '- ✅ **NotionNext 版本号**(例如:4.9.4.2)', |
| 137 | + '- ✅ **使用的主题**(例如:hexo / heo / next)', |
| 138 | + '- ✅ **部署方案**(例如:Vercel / Cloudflare Pages / 自托管)', |
| 139 | + '- ✅ **复现步骤**(清晰的步骤描述)', |
| 140 | + '- ✅ **期望结果与实际结果**', |
| 141 | + '', |
| 142 | + '如果以上信息不完整,请补充后我们会继续跟进。感谢您对 NotionNext 的贡献! 🙏', |
| 143 | + ].join('\n'); |
| 144 | +
|
| 145 | + const enhancementComment = [ |
| 146 | + `👋 @${author} 感谢您提交新特性建议!`, |
| 147 | + '', |
| 148 | + '您的建议已被收录,我们将在评估可行性后决定是否纳入后续版本。', |
| 149 | + '', |
| 150 | + '如果您有能力参与实现,欢迎提交 PR!具体开发规范请参阅 [贡献指南](https://github.com/tangly1024/NotionNext/blob/main/README.md)。', |
| 151 | + '', |
| 152 | + '感谢您对 NotionNext 的支持! 🙏', |
| 153 | + ].join('\n'); |
| 154 | +
|
| 155 | + const deploymentComment = [ |
| 156 | + `👋 @${author} 感谢您反馈部署问题!`, |
| 157 | + '', |
| 158 | + '以下是常见部署问题的排查建议,请先自查:', |
| 159 | + '', |
| 160 | + '1. 📝 确认 `NOTION_PAGE_ID` 已正确配置并且 Notion 页面已公开分享。', |
| 161 | + '2. 🔑 确认所有必要的环境变量(如 `NEXT_PUBLIC_*`)已在部署平台正确设置。', |
| 162 | + '3. 📦 确认使用的 Node.js 版本为 20.x(兼容 20/22/24),依赖安装命令为 `yarn`。', |
| 163 | + '4. 📖 参阅官方文档:[部署指南](https://github.com/tangly1024/NotionNext#部署)', |
| 164 | + '', |
| 165 | + '如果以上步骤均已确认,请补充更详细的错误日志,我们将继续协助排查。感谢您的耐心! 🙏', |
| 166 | + ].join('\n'); |
| 167 | +
|
| 168 | + const helpComment = [ |
| 169 | + `👋 @${author} 您好,感谢您使用 NotionNext!`, |
| 170 | + '', |
| 171 | + '请详细描述您遇到的问题以及期望的结果,以便社区成员更好地帮助您。', |
| 172 | + '', |
| 173 | + '同时也欢迎加入我们的社区交流群获取更快速的帮助:[Telegram 群组](https://t.me/Notionso)', |
| 174 | + '', |
| 175 | + '感谢您的使用! 🙏', |
| 176 | + ].join('\n'); |
| 177 | +
|
| 178 | + const defaultComment = [ |
| 179 | + `👋 @${author} 感谢您提交 Issue!`, |
| 180 | + '', |
| 181 | + '我们已收到您的反馈,将尽快处理。如有需要,我们会与您进一步沟通。', |
| 182 | + '', |
| 183 | + '欢迎加入我们的社区:[Telegram 群组](https://t.me/Notionso)', |
| 184 | + '', |
| 185 | + '感谢您对 NotionNext 的支持! 🙏', |
| 186 | + ].join('\n'); |
| 187 | +
|
| 188 | + if (labels.includes('bug')) return bugComment; |
| 189 | + if (labels.includes('enhancement')) return enhancementComment; |
| 190 | + if (labels.includes('deployment')) return deploymentComment; |
| 191 | + if (labels.includes('help wanted')) return helpComment; |
| 192 | + return defaultComment; |
| 193 | + }; |
| 194 | +
|
| 195 | + let processed = 0; |
| 196 | + for (const issue of issues) { |
| 197 | + if (issue.pull_request) continue; |
| 198 | + if (issue.comments > 0) continue; |
| 199 | +
|
| 200 | + const labels = issue.labels.map(l => l.name); |
| 201 | + const comment = buildComment(issue.user.login, labels); |
| 202 | +
|
| 203 | + await github.rest.issues.createComment({ |
| 204 | + owner: context.repo.owner, |
| 205 | + repo: context.repo.repo, |
| 206 | + issue_number: issue.number, |
| 207 | + body: comment, |
| 208 | + }); |
| 209 | +
|
| 210 | + processed++; |
| 211 | + await new Promise(r => setTimeout(r, 1000)); |
| 212 | + } |
| 213 | +
|
| 214 | + console.log(`每日巡检完成,共处理 ${processed} 个 Issue。`); |
0 commit comments