|
56 | 56 | console.log(`Using hardcoded current version: ${currentVersion}`); |
57 | 57 | } |
58 | 58 | |
59 | | - // 获取允许的版本号列表函数 |
| 59 | + // 版本比较函数 |
| 60 | + function compareVersions(version1, version2) { |
| 61 | + function parseVersion(versionStr) { |
| 62 | + const parts = versionStr.split('-'); |
| 63 | + const versionParts = parts[0].split('.').map(Number); |
| 64 | + return { |
| 65 | + major: versionParts[0] || 0, |
| 66 | + minor: versionParts[1] || 0, |
| 67 | + patch: versionParts[2] || 0, |
| 68 | + suffix: parts[1] || '', |
| 69 | + full: versionStr |
| 70 | + }; |
| 71 | + } |
| 72 | + |
| 73 | + const v1 = parseVersion(version1); |
| 74 | + const v2 = parseVersion(version2); |
| 75 | + |
| 76 | + if (v1.major !== v2.major) return v1.major - v2.major; |
| 77 | + if (v1.minor !== v2.minor) return v1.minor - v2.minor; |
| 78 | + if (v1.patch !== v2.patch) return v1.patch - v2.patch; |
| 79 | + |
| 80 | + // 处理后缀比较(beta < 正式版) |
| 81 | + if (v1.suffix && !v2.suffix) return -1; |
| 82 | + if (!v1.suffix && v2.suffix) return 1; |
| 83 | + if (v1.suffix && v2.suffix) return v1.suffix.localeCompare(v2.suffix); |
| 84 | + |
| 85 | + return 0; |
| 86 | + } |
| 87 | + |
| 88 | + // 检查版本是否比当前版本更新 |
| 89 | + function isNewerVersion(reportedVer, currentVer) { |
| 90 | + return compareVersions(reportedVer, currentVer) > 0; |
| 91 | + } |
| 92 | + |
| 93 | + // 获取允许的版本号列表函数(仅用于显示支持的版本) |
60 | 94 | function getAllowedVersions(currentVer, gap) { |
61 | 95 | function parseVersion(versionStr) { |
62 | 96 | const parts = versionStr.split('-'); |
@@ -108,10 +142,28 @@ jobs: |
108 | 142 | return allowedVersions; |
109 | 143 | } |
110 | 144 | |
111 | | - // 格式化允许版本号的列表 |
| 145 | + // 检查版本是否在允许范围内(包括当前版本、较早版本和更新版本) |
| 146 | + function isVersionAllowed(reportedVer, currentVer, gap) { |
| 147 | + const allowedVersions = getAllowedVersions(currentVer, gap); |
| 148 | + |
| 149 | + // 检查是否在允许的版本列表中 |
| 150 | + if (allowedVersions.includes(reportedVer)) { |
| 151 | + return true; |
| 152 | + } |
| 153 | + |
| 154 | + // 检查是否是更新的版本 |
| 155 | + if (isNewerVersion(reportedVer, currentVer)) { |
| 156 | + console.log(`Version ${reportedVer} is newer than current ${currentVer}, allowing it.`); |
| 157 | + return true; |
| 158 | + } |
| 159 | + |
| 160 | + return false; |
| 161 | + } |
| 162 | + |
| 163 | + // 格式化允许版本号的列表(仅显示支持的版本,不包括未来版本) |
112 | 164 | const allowedVersions = getAllowedVersions(currentVersion, VERSION_GAP); |
113 | 165 | const formattedAllowedVersions = allowedVersions.map(v => `\`${v}\``).join(', '); |
114 | | - console.log(`Allowed versions: ${JSON.stringify(allowedVersions)}`); |
| 166 | + console.log(`Displayed allowed versions: ${JSON.stringify(allowedVersions)}`); |
115 | 167 | |
116 | 168 | // 获取所有 bot 之前的评论 |
117 | 169 | const comments = await github.rest.issues.listComments({ |
@@ -190,8 +242,8 @@ jobs: |
190 | 242 | const reportedVersion = match[1]; |
191 | 243 | console.log(`Reported version: ${reportedVersion}`); |
192 | 244 | |
193 | | - // 检查版本是否在允许的范围内 |
194 | | - if (allowedVersions.includes(reportedVersion)) { |
| 245 | + // 检查版本是否在允许的范围内(包括更新版本) |
| 246 | + if (isVersionAllowed(reportedVersion, currentVersion, VERSION_GAP)) { |
195 | 247 | console.log('Version is within allowed range. No action needed.'); |
196 | 248 | |
197 | 249 | // 如果 issue 被标记为过时版本或无效格式,但现在版本正确,移除这些标签并重新打开 issue |
@@ -225,11 +277,16 @@ jobs: |
225 | 277 | state: 'open' |
226 | 278 | }); |
227 | 279 | |
| 280 | + // 为更新版本添加特殊提示 |
| 281 | + const isNewer = isNewerVersion(reportedVersion, currentVersion); |
| 282 | + const versionNote = isNewer ? |
| 283 | + `\n\n**注意:** 您使用的版本 (\`${reportedVersion}\`) 比当前仓库版本更新,我们已接受此报告。\n\n**Note:** You're using a version (\`${reportedVersion}\`) that's newer than the current repository version, and we've accepted this report.` : ''; |
| 284 | + |
228 | 285 | await github.rest.issues.createComment({ |
229 | 286 | owner: context.repo.owner, |
230 | 287 | repo: context.repo.repo, |
231 | 288 | issue_number: issue.number, |
232 | | - body: `## 版本验证通过,问题已重新打开 / Version Verified, Issue Reopened\n\n非常感谢您更新了问题报告!您现在使用的版本 (\`${reportedVersion}\`) 是受支持的版本,我们已自动重新打开这个问题。我们的团队将尽快查看并处理您的反馈。\n\n感谢您对 GTO 项目的支持与贡献!\n\n---\n\nThank you for updating your report! The version you're using now (\`${reportedVersion}\`) is supported, and we've automatically reopened this issue. Our team will review and address your feedback as soon as possible.\n\nWe appreciate your support and contributions to the GTO project!` |
| 289 | + body: `## 版本验证通过,问题已重新打开 / Version Verified, Issue Reopened\n\n非常感谢您更新了问题报告!您现在使用的版本 (\`${reportedVersion}\`) 是受支持的版本,我们已自动重新打开这个问题。我们的团队将尽快查看并处理您的反馈。${versionNote}\n\n感谢您对 GTO 项目的支持与贡献!\n\n---\n\nThank you for updating your report! The version you're using now (\`${reportedVersion}\`) is supported, and we've automatically reopened this issue. Our team will review and address your feedback as soon as possible.${versionNote}\n\nWe appreciate your support and contributions to the GTO project!` |
233 | 290 | }); |
234 | 291 | } |
235 | 292 | |
|
0 commit comments