Skip to content

Commit

Permalink
♻️ (workflow): 优化 Issue 处理流程并增强错误处理
Browse files Browse the repository at this point in the history
- 使用环境变量动态获取仓库所有者和仓库名称
- 分页获取所有开放的 Issue,避免一次性加载过多数据
- 增强日志输出,提供更详细的处理信息
- 改进错误处理,捕获并记录每个 Issue 处理中的错误
  • Loading branch information
AnkioTomas committed Dec 18, 2024
1 parent 95429cf commit 00a5018
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions .github/workflows/testRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,38 +144,70 @@ async function processIssue () {
}
}

async function processAll () {
async function processAll() {
try {
// 初始化 Octokit
const token = process.env.GITHUB_TOKEN;
const octokit = new Octokit({ auth: token });
const { data: issues } = await octokit.rest.issues.listForRepo({
owner: "AutoAccountingOrg",
repo: "AutoRule",
state: 'open'
});
const owner = process.env.GITHUB_REPOSITORY_OWNER;
const repo = process.env.GITHUB_REPOSITORY.split('/')[1];

console.log(`Fetching issues for ${owner}/${repo}...`);

// 分页获取所有 Issue
let allIssues = [];
let page = 1;
const perPage = 100;

while (true) {
const { data: issues } = await octokit.rest.issues.listForRepo({
owner,
repo,
state: 'open',
per_page: perPage,
page,
});

allIssues = allIssues.concat(issues);

if (issues.length < perPage) {
break; // 没有更多的 Issue
}

for (const issue of issues) {
console.log(`Issue #${issue.number}: ${issue.title}`);
page++;
}

console.log(`Found ${allIssues.length} open issues.`);

// 逐个处理 Issue
for (const issue of allIssues) {
console.log(`Processing Issue #${issue.number}: ${issue.title}`);
console.log(`Content: ${issue.body}`);

try {
// 提取代码块
const codeBlock = await extractCodeBlockSync(issue.body);
writeToFile(codeBlock);

// 运行 Yarn 命令并提取结果
const output = await runYarnCommands();
const result = extractTestResult(output);

if (result) {
// 处理结果
await handleIssue(issue.number, result);
} else {
console.log('未找到===========START===========和===========END===========之间的内容');
console.warn(
`No content found between ===========START=========== and ===========END=========== for Issue #${issue.number}`
);
}
} catch (e) {
console.log(`处理issue出错:${issue.number}`);
} catch (issueError) {
console.error(`Error processing Issue #${issue.number}: ${issueError.message}`);
}
}
} catch (error) {
console.error(`Error fetching issues: ${error.message}`);
process.exit(1);
console.error(`Error fetching or processing issues: ${error.message}`);
process.exit(1); // 强制退出
}
}

Expand Down

0 comments on commit 00a5018

Please sign in to comment.