fix: 修复代码审查反馈 - URL编码、标签匹配、错误处理

- 修复 GitHub API 日期过滤的 URL 编码
- 移除未使用的 getJobLog 函数
- 改进 pending 标签移除的错误处理
- 修复工作流中标签匹配逻辑

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-07 06:26:53 +00:00
parent d91d1b037b
commit d29a6565f9
2 changed files with 8 additions and 16 deletions

View File

@ -48,7 +48,7 @@ jobs:
contains(github.event.comment.body, '部署诊断') ||
contains(github.event.comment.body, '检查部署')
)) ||
(github.event_name == 'issues' && contains(toJSON(github.event.issue.labels), 'bingshuo-deploy'))
(github.event_name == 'issues' && contains(join(github.event.issue.labels.*.name, ','), 'bingshuo-deploy'))
steps:
- name: 📥 检出代码

View File

@ -92,7 +92,7 @@ function githubAPI(method, path, data) {
async function getRecentRuns() {
const since = new Date(Date.now() - HOURS_BACK * 60 * 60 * 1000).toISOString();
const result = await githubAPI('GET',
`/repos/${OWNER}/${REPO_NAME}/actions/runs?per_page=100&created=>${since}`
`/repos/${OWNER}/${REPO_NAME}/actions/runs?per_page=100&created=%3E${since}`
);
if (result.status !== 200) {
console.error('❌ 获取工作流运行记录失败:', result.status);
@ -110,17 +110,6 @@ async function getJobsForRun(runId) {
return result.data.jobs || [];
}
// === 获取某个作业的日志最后200行===
async function getJobLog(jobId) {
// GitHub API 返回日志的重定向URL
const result = await githubAPI('GET',
`/repos/${OWNER}/${REPO_NAME}/actions/jobs/${jobId}/logs`
);
// 日志接口返回 302 重定向,但我们的简单 HTTPS 客户端无法跟随
// 改用 jobs 接口获取步骤信息作为替代
return null;
}
// === 从 jobs 中提取失败信息 ===
function extractFailureInfo(jobs) {
const failures = [];
@ -392,10 +381,13 @@ async function postReport(report) {
`/repos/${OWNER}/${REPO_NAME}/issues/${ISSUE_NUMBER}/labels`,
{ labels: ['🧊deploy-report', '✅answered'] }
);
// 移除 pending 标签
await githubAPI('DELETE',
// 移除 pending 标签如果不存在会返回404属正常情况
const removeResult = await githubAPI('DELETE',
`/repos/${OWNER}/${REPO_NAME}/issues/${ISSUE_NUMBER}/labels/${encodeURIComponent('pending')}`
).catch(() => null);
);
if (removeResult.status !== 200 && removeResult.status !== 404) {
console.warn('⚠️ 移除 pending 标签时出现异常:', removeResult.status);
}
console.log(`✅ 报告已发布到 Issue #${ISSUE_NUMBER}`);
} else {