Skip to content

[其他] 全新安装的WithRuntime版,每次启动都提示目标版本的运行环境与当前不兼容,然后资源下载界面显示为原始启动器而非集成启动器 #700

[其他] 全新安装的WithRuntime版,每次启动都提示目标版本的运行环境与当前不兼容,然后资源下载界面显示为原始启动器而非集成启动器

[其他] 全新安装的WithRuntime版,每次启动都提示目标版本的运行环境与当前不兼容,然后资源下载界面显示为原始启动器而非集成启动器 #700

name: issue_automation
on:
issues:
types: [opened]
jobs:
process_issue:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'OneDragon-Anything' }}
permissions:
contents: read
issues: write
steps:
- name: 获取Issue信息
id: get_issue_info
uses: actions/github-script@v7
with:
script: |
const issueBody = context.payload.issue.body || '';
const issueTitle = context.payload.issue.title;
const issueNumber = context.payload.issue.number;
const normalizedIssueBody = issueBody.replace(/\r\n/g, '\n');
const targetOwner = context.repo.owner;
const targetRepo = context.repo.repo;
function escapeRegExp(value) {
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
function extractSectionValue(body, label) {
const sectionRegex = new RegExp(`(?:^|\\r?\\n)### ${escapeRegExp(label)}\\s*\\r?\\n+([\\s\\S]*?)(?=\\r?\\n### |$)`);
const match = body.match(sectionRegex);
if (!match) {
return '';
}
return match[1]
.split('\n')
.map((line) => line.trim())
.find(Boolean) || '';
}
function extractCommitHash(value) {
const match = value.match(/\b[0-9a-fA-F]{7,40}\b/);
return match ? match[0].toLowerCase() : '';
}
const issueType = extractSectionValue(normalizedIssueBody, '问题类型');
const issueScope = extractSectionValue(normalizedIssueBody, '问题范围');
const reportedCodeVersion = extractSectionValue(normalizedIssueBody, '代码版本');
const reportedCommitHash = extractCommitHash(reportedCodeVersion);
// 1. 检查“未认真阅读”选项并处理
const isMisread = normalizedIssueBody.includes('- [x] 未认真阅读此处选项随意勾选') || normalizedIssueBody.includes('- [X] 未认真阅读此处选项随意勾选');
if (isMisread) {
console.log('检测到“未认真阅读”选项被勾选。');
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: ['Invalid | 无效反馈']
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: '感谢你的反馈。此 Issue 未能遵循反馈要求,因此已被标记为“无效”并关闭。请仔细阅读并按照要求重新提交。'
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
state: 'closed',
state_reason: 'not_planned',
});
console.log('Issue 已被标记为“无效”并关闭。');
return;
}
// 2. 根据问题类型添加标签
let issueTypeLabel = '';
if (issueType === 'Bug') {
issueTypeLabel = 'Bug | 工作不正常';
} else if (issueType === '更新建议') {
issueTypeLabel = 'Enhancement | 增强';
} else if (issueType === '新版本修改') {
issueTypeLabel = 'Adapting | 等待适配';
}
if (issueTypeLabel) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
labels: [issueTypeLabel]
});
console.log(`已添加问题类型标签: ${issueTypeLabel}`);
}
// 3. 根据问题范围重命名标题
let scopePrefix = '';
if (issueScope === '自动战斗') {
scopePrefix = '[自动战斗] ';
} else if (issueScope === '一条龙日常') {
scopePrefix = '[一条龙日常] ';
} else if (issueScope === '迷失之地') {
scopePrefix = '[迷失之地] ';
} else if (issueScope === '游戏助手') {
scopePrefix = '[游戏助手] ';
} else if (issueScope === '其他') {
scopePrefix = '[其他] ';
}
let newTitle = issueTitle;
if (scopePrefix && !issueTitle.startsWith(scopePrefix)) { // 避免重复添加前缀
newTitle = scopePrefix + issueTitle;
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
title: newTitle
});
console.log(`Issue 标题已更新为: ${newTitle}`);
}
// 4. 检查代码版本是否为主仓库任一分支的最新提交
if (!reportedCommitHash) {
console.log(`未从“代码版本”字段解析到有效哈希,原始内容: ${reportedCodeVersion || '空'}`);
return;
}
try {
const branches = await github.paginate(github.rest.repos.listBranches, {
owner: targetOwner,
repo: targetRepo,
per_page: 100,
});
const matchedBranch = branches.find((branch) => {
const latestCommitHash = branch.commit.sha.toLowerCase();
return reportedCommitHash.length < latestCommitHash.length
? latestCommitHash.startsWith(reportedCommitHash)
: reportedCommitHash === latestCommitHash;
});
if (!matchedBranch) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: [
`检测到你填写的代码版本不是主仓库 ${targetOwner}/${targetRepo} 任一分支的最新版本。`,
'请先同步代码到最新版本后,再确认该问题是否仍然存在;若更新后仍可复现,请补充最新版本的日志和截图。',
'',
`- 当前填写版本:${reportedCommitHash}`,
`- 检查范围:${targetOwner}/${targetRepo} 的全部分支`,
].join('\n')
});
console.log(`Issue #${issueNumber} 填写的代码版本不是任一分支的最新版本: ${reportedCommitHash}`);
} else {
console.log(`Issue #${issueNumber} 填写的代码版本命中分支 ${matchedBranch.name} 的最新版本: ${reportedCommitHash}`);
}
} catch (error) {
console.error(`检查 Issue #${issueNumber} 的代码版本失败`, error);
}