From ceb46d5c114864ce532ece4f5e636ea894ae7ee4 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 28 Jul 2026 00:40:21 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(ci):=20=E6=A0=BC=E5=BC=8F=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E4=BF=AE=E5=A4=8D=E5=AF=B9=E6=89=80=E6=9C=89PR?= =?UTF-8?q?=E5=BC=80=E6=94=BE=20+=20=E9=98=B2=E5=BE=AA=E7=8E=AF=E6=9C=BA?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 去掉Agent-only限制,所有PR格式问题自动修复 - 添加[skip ci-format-check]防循环标记 - 同步main版本 --- scripts/ci/auto_fix_formatting.py | 57 +++++++++++++------------------ 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/scripts/ci/auto_fix_formatting.py b/scripts/ci/auto_fix_formatting.py index f4e493e3d..1d927af58 100755 --- a/scripts/ci/auto_fix_formatting.py +++ b/scripts/ci/auto_fix_formatting.py @@ -1,8 +1,10 @@ #!/usr/bin/env python3 """CI中自动修复代码格式(Python: black + isort | Frontend: prettier),并推送回原分支。 -- PR事件:自动修复并push回PR源分支(Agent提交的PR自动修,人提交的仅诊断) +- PR事件:所有PR只要Code Quality因格式问题失败,自动修复并push回源分支 - Push事件(develop/main):自动修复并push回原分支,保持主干格式永远正确 +- 防循环:修复commit带 [skip ci-format-check] 标记,检测到该标记则跳过修复 +- 只修格式(black/isort/prettier),ruff逻辑类错误不动 当code quality检查因格式问题失败时触发。 """ @@ -239,7 +241,7 @@ def main(): print("无法获取PR号,跳过自动修复") return - # 获取PR作者信息,判断是人还是Agent提交的 + # 获取PR信息 pr_info_url = f"{api_url}/repos/{repo}/pulls/{pr_number}" req_pr = urllib.request.Request(pr_info_url, headers={"Authorization": f"token {token}"}) with urllib.request.urlopen(req_pr) as resp: @@ -247,17 +249,26 @@ def main(): pr_author = pr_info.get("user", {}).get("login", "") print(f"PR作者: {pr_author}") - # 判断是否为Agent提交的PR - agent_authors = {"actions", "auto-approve-bot", "gitea-actions"} - is_agent_pr = pr_author in agent_authors or "bot" in pr_author.lower() + # 防循环检测:检查最新commit是否已经是格式修复commit + # 修复commit message 带 [skip ci-format-check] 标记,检测到则跳过 + head_branch_tmp = pr_info.get("head", {}).get("ref", "") + skip_marker = "[skip ci-format-check]" + try: + commits_url = f"{api_url}/repos/{repo}/pulls/{pr_number}/commits?limit=3" + req_commits = urllib.request.Request(commits_url, headers={"Authorization": f"token {token}"}) + with urllib.request.urlopen(req_commits) as resp_commits: + commits = json.loads(resp_commits.read()) + latest_msg = commits[-1].get("commit", {}).get("message", "") if commits else "" + if skip_marker in latest_msg: + print(f"检测到最新commit包含 {skip_marker} 标记,跳过格式修复(防循环)") + print("本次格式检查失败是格式修复commit触发的CI回跑,属正常现象") + sys.exit(0) + except Exception as e: + print(f"⚠️ 防循环检测失败,继续执行: {e}") - if is_agent_pr: - print(f"检测到Agent提交的PR(作者: {pr_author}),将自动修复并推送") - fix_mode = "auto_fix_and_push" - else: - print(f"检测到人提交的PR(作者: {pr_author}),仅诊断不自动修改") - print("(如需自动修复,请用Agent账号提交PR,或手动运行格式化脚本)") - fix_mode = "diagnose_only" + # 所有PR都自动修复格式(不再区分人/Agent) + print("检测到格式问题,将自动修复并推送回分支") + fix_mode = "auto_fix_and_push" print("=== 检测到代码格式问题,尝试自动修复 ===") print(f"PR #{pr_number}") @@ -315,26 +326,6 @@ def main(): print("没有需要提交的格式改动") return - # 诊断模式:只报告问题,不修改不推送 - if fix_mode == "diagnose_only": - print() - print("=" * 50) - print("📋 格式问题诊断报告(人提交的PR,仅诊断不自动修复)") - print("=" * 50) - print() - print("以下文件存在格式问题,建议手动修复:") - for line in result.stdout.strip().split("\n"): - print(f" {line}") - print() - print("修复方式:") - print(" 后端(Python): 运行 black + isort") - print(" 前端: 运行 prettier --write") - print(" 或使用 scripts/agent-commit.sh 提交(自动格式化)") - print() - print("=" * 50) - # 以非0状态码退出,让CI继续报失败(因为问题没修) - sys.exit(1) - print() print("变更文件:") for line in result.stdout.strip().split("\n"): @@ -342,7 +333,7 @@ def main(): # 提交修复 run("git add -A") - run('git commit -m "style: auto-format with black + isort + prettier"') + run('git commit -m "style: auto-format with black + isort + prettier [skip ci-format-check]"') # 推送(head_branch已从ensure_git_repo获取) print(f"\nPR来源分支: {head_branch}") -- 2.54.0 From be196cc2ccbcc93c0e20c4827ea1817a0111571f Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 28 Jul 2026 08:19:36 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E9=98=B2=E5=BE=AA=E7=8E=AF=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E5=8F=96=E6=9C=80=E6=96=B0commit=EF=BC=88API=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=92=E5=BA=8F=EF=BC=8C=E7=94=A8[0]=E8=80=8C?= =?UTF-8?q?=E9=9D=9E[-1]=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci/auto_fix_formatting.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci/auto_fix_formatting.py b/scripts/ci/auto_fix_formatting.py index 1d927af58..bc32c5308 100755 --- a/scripts/ci/auto_fix_formatting.py +++ b/scripts/ci/auto_fix_formatting.py @@ -258,7 +258,7 @@ def main(): req_commits = urllib.request.Request(commits_url, headers={"Authorization": f"token {token}"}) with urllib.request.urlopen(req_commits) as resp_commits: commits = json.loads(resp_commits.read()) - latest_msg = commits[-1].get("commit", {}).get("message", "") if commits else "" + latest_msg = commits[0].get("commit", {}).get("message", "") if commits else "" if skip_marker in latest_msg: print(f"检测到最新commit包含 {skip_marker} 标记,跳过格式修复(防循环)") print("本次格式检查失败是格式修复commit触发的CI回跑,属正常现象") -- 2.54.0 From 3eccd91ebb15fb9711d9a87a6322302e8971b0cc Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Tue, 28 Jul 2026 09:00:34 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix(ci):=20AI=20Code=20Review=20fail-open?= =?UTF-8?q?=20-=20LLM=E5=A4=B1=E8=B4=A5/=E5=BC=82=E5=B8=B8=E6=97=B6?= =?UTF-8?q?=E4=B8=8D=E9=98=BB=E5=A1=9E=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci_code_review.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ci_code_review.py b/scripts/ci_code_review.py index 1ec5e8330..c67bf88d9 100644 --- a/scripts/ci_code_review.py +++ b/scripts/ci_code_review.py @@ -715,7 +715,7 @@ def main(): if not review_result: logger.error("LLM 审查失败") - sys.exit(1) + sys.exit(0) # fail-open: LLM调用失败不阻塞合并 # 7. 加上审查时间和标识(便于识别是自动审查) from datetime import datetime @@ -773,7 +773,7 @@ def main(): except Exception as e: logger.exception(f"审查脚本发生未预期的异常: {e}") - sys.exit(1) + sys.exit(0) # fail-open: 异常不阻塞正常开发 if __name__ == "__main__": -- 2.54.0