fix(ci): 格式化pr_auto_scan.py修复develop分支Code Quality门禁 #741

Merged
xiaoxia merged 1 commits from fix/ci-pr-auto-scan-black-format into develop 2026-07-22 20:52:24 +08:00
Owner

问题

develop分支Code Quality门禁失败,原因是scripts/ci/pr_auto_scan.py(#722新增)未通过black格式检查。

修复

  • black格式化 pr_auto_scan.py
  • isort整理import

影响

  • 修复develop分支Code Quality失败问题
  • 不影响业务逻辑
## 问题 develop分支Code Quality门禁失败,原因是`scripts/ci/pr_auto_scan.py`(#722新增)未通过black格式检查。 ## 修复 - black格式化 pr_auto_scan.py - isort整理import ## 影响 - 修复develop分支Code Quality失败问题 - 不影响业务逻辑
xiaoxia added 1 commit 2026-07-22 20:32:03 +08:00
fix(ci): 格式化pr_auto_scan.py修复develop分支Code Quality门禁
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 41s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 49s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 53s
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 56s
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m2s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 43s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 2m34s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m39s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 2m43s
AI Code Review / AI Code Review (pull_request) Successful in 3m45s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 4m41s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m59s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 5m8s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 13m0s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 9s
b1913f48e2

🚀 预览环境已部署

项目 详情
PR号 #741
预览链接 https://pr-741.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #741 | | 预览链接 | [https://pr-741.preview.xiaoxiajianji.com](https://pr-741.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
Collaborator

代码审查结果 - PR #741

⚠️ 问题(4个需要修改)

  1. scripts/ci/pr_auto_scan.py 第40行e.read() 在条件表达式中被调用了两次。第一次调用消耗了错误流,导致第二次调用返回空字节,json.loads 解析空字符串将抛出 JSONDecodeError 异常,导致错误处理失败。
  2. scripts/ci/pr_auto_scan.py 第26-28行:SSL证书验证被完全禁用(verify_mode = ssl.CERT_NONE),虽然在内网环境常见,但存在中间人攻击(MITM)的安全隐患。
  3. scripts/ci/pr_auto_scan.py 第163行merge_pr 函数中硬编码 time.sleep(30)。默认 max-prs 为 20,若处理多个 PR,总阻塞时间可能超过 10 分钟,导致脚本运行时长超过 5 分钟的调度间隔,造成作业重叠或积压。
  4. scripts/ci/pr_auto_scan.py 第268行check_required_contexts 内部调用了 get_commit_status API。在 main 函数中,针对同一个 SHA 分别调用了两次(第 268 行和第 291 行)来检查不同的上下文,导致重复的 API 请求,浪费资源且增加延迟。

💡 建议(1个可选)

  1. scripts/ci/pr_auto_scan.py 第244行get_open_prs 已经通过 base 参数向 API 发起了过滤请求,此处 if base_ref != args.base 的检查显得冗余,除非为了防御 API 返回异常数据,否则可移除。

格式检查通过 | 逻辑审查需修改 | ⚠️ 建议关注性能


🤖 由 AI 代码审查机器人自动生成 | 2026-07-22 20:35:51 | 模型:

## 代码审查结果 - PR #741 ### ⚠️ 问题(4个需要修改) 1. **scripts/ci/pr_auto_scan.py 第40行**:`e.read()` 在条件表达式中被调用了两次。第一次调用消耗了错误流,导致第二次调用返回空字节,`json.loads` 解析空字符串将抛出 `JSONDecodeError` 异常,导致错误处理失败。 2. **scripts/ci/pr_auto_scan.py 第26-28行**:SSL证书验证被完全禁用(`verify_mode = ssl.CERT_NONE`),虽然在内网环境常见,但存在中间人攻击(MITM)的安全隐患。 3. **scripts/ci/pr_auto_scan.py 第163行**:`merge_pr` 函数中硬编码 `time.sleep(30)`。默认 `max-prs` 为 20,若处理多个 PR,总阻塞时间可能超过 10 分钟,导致脚本运行时长超过 5 分钟的调度间隔,造成作业重叠或积压。 4. **scripts/ci/pr_auto_scan.py 第268行**:`check_required_contexts` 内部调用了 `get_commit_status` API。在 `main` 函数中,针对同一个 SHA 分别调用了两次(第 268 行和第 291 行)来检查不同的上下文,导致重复的 API 请求,浪费资源且增加延迟。 ### 💡 建议(1个可选) 1. **scripts/ci/pr_auto_scan.py 第244行**:`get_open_prs` 已经通过 `base` 参数向 API 发起了过滤请求,此处 `if base_ref != args.base` 的检查显得冗余,除非为了防御 API 返回异常数据,否则可移除。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ⚠️ 建议关注性能 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-22 20:35:51 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit a75f749b39 into develop 2026-07-22 20:52:24 +08:00
xiaoxia deleted branch fix/ci-pr-auto-scan-black-format 2026-07-22 20:52:24 +08:00

🗑️ 预览环境已清理

PR #741 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #741 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.