From b59cf8aab55e75e95da4cfe44a9b4b9a97c0ed65 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 22 Jul 2026 08:12:53 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E8=87=AA=E5=8A=A8=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E4=BF=AE=E5=A4=8D=E5=8C=BA=E5=88=86Agent/=E4=BA=BA?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=EF=BC=8C=E4=BA=BA=E6=8F=90=E4=BA=A4=E7=9A=84?= =?UTF-8?q?PR=E4=BB=85=E8=AF=8A=E6=96=AD=E4=B8=8D=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20(#694)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci/auto_fix_formatting.py | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/scripts/ci/auto_fix_formatting.py b/scripts/ci/auto_fix_formatting.py index b6470c642..595973151 100755 --- a/scripts/ci/auto_fix_formatting.py +++ b/scripts/ci/auto_fix_formatting.py @@ -168,6 +168,28 @@ def main(): return api_url = os.environ.get("GITHUB_API_URL", "") + + # 获取PR作者信息,判断是人还是Agent提交的 + 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: + pr_info = json.loads(resp.read()) + pr_author = pr_info.get("user", {}).get("login", "") + print(f"PR作者: {pr_author}") + + # 判断是否为Agent提交的PR + # Agent账号:actions, auto-approve-bot 等bot用户 + # 人提交的PR(如xiaoxia):只诊断不自动修 + agent_authors = {"actions", "auto-approve-bot", "gitea-actions"} + is_agent_pr = pr_author in agent_authors or "bot" in pr_author.lower() + + 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" repo = os.environ.get("GITHUB_REPOSITORY", "") token = os.environ.get("GITHUB_TOKEN", "") scan_mode = os.environ.get("SCAN_MODE", "full") @@ -231,6 +253,26 @@ 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"):