如何在 2025 年向 Gunicorn 官方提交一个 PR 并通过 DCO 检查?

解读

面试官想确认三件事:

  1. 你是否熟悉 Gunicorn 2025 年的官方协作流程(GitHub 已强制启用 DCO 签名 与 双因子身份验证)。
  2. 你是否能在国内网络环境下完成 合规的 Git 配置、镜像加速、issue 关联 与 CI 通过。
  3. 你是否理解 DCO 与 CLA 的区别,并能在命令行一次性通过检查,避免“push -f”污染历史。

知识点

  1. DCO(Developer Certificate of Origin):每条 commit 必须有 Signed-off-by: 行,证明你有权提交。
  2. GitHub 镜像:国内使用 ghproxy.com 或 gitclone.com 加速 git clone https://github.com/benoitc/gunicorn.git。
  3. pre-commit 钩子:Gunicorn 2025 年仓库自带 .pre-commit-config.yaml,强制运行 ruff、mypy、dco-check。
  4. issue 模板:必须引用 Fix #xxxx 或 Relates to #xxxx,否则 CI 机器人自动关闭 PR。
  5. worker 类型回归测试:提交代码后,CI 会在 ubuntu-24.04、alpine-3.20、python-3.13 矩阵下跑 tox -e py313-sync,py313-uvloop,py313-gevent。
  6. 国内 GPG 签名:若使用 GPG,需把公钥上传到 GitHub 并配置 git config --global gpg.program gpg2,否则 DCO bot 会报 “Unsigned commit”。
  7. rebase 策略:Gunicorn 官方要求一个 feature 一个 commit,禁止 merge commit,必须使用 git rebase -i 压缩。

答案

步骤如下,全部在境内可复现:

  1. 环境准备

    • 安装 Python 3.13、git ≥ 2.45、tox ≥ 4.0、pre-commit ≥ 3.7。
    • 配置 Git 用户:
      git config --global user.name "Li Lei"
      git config --global user.email "lilei@example.com"
      git config --global core.autocrlf input
      git config --global commit.gpgsign true   # 若已启用 GPG
      
    • 通过 ghproxy.com 加速克隆:
      git clone https://hub.gitclone.com/https://github.com/benoitc/gunicorn.git
      cd gunicorn
      
  2. 创建分支并开发

    • 基于最新 main 创建功能分支:
      git checkout -b fix-2025-dco-demo
      
    • 编写代码,确保新增单元测试位于 tests/workers/test_sync.py,覆盖率不低于 95%。
  3. 本地质量门禁

    • 安装钩子:
      pre-commit install --hook-type commit-msg
      
    • 运行检查:
      tox -e lint,type,test
      
    • 若 DCO 钩子报错,用 git commit --amend --signoff 补签。
  4. 提交并推送

    • 单 commit 提交:
      git add .
      git commit -s -m "worker: fix fd leak on reload
      
      Relates to #2345
      
      Signed-off-by: Li Lei <lilei@example.com>"
      
    • 推送:
      git push origin fix-2025-dco-demo
      
  5. 创建 PR

    • 在 GitHub 页面勾选 “Allow edits by maintainers”,模板中填写:
      • 问题描述
      • 复现步骤
      • 测试脚本
      • 回归结果截图文本
    • 确认 “Commits” 标签页每条都有 Verified 与 Signed-off-by。
  6. CI 通过

    • 等待 GitHub Actions 全部绿灯,若出现 alpine-3.20 镜像拉取超时,可在 PR 评论 /retry-ci 触发重跑。
    • 若 DCO bot 仍报错,本地 git rebase HEAD~1 --signoff 后 git push -f。
  7. 维护人评审

    • 响应 review 意见,48 小时内 force-push 更新;每次更新仍保持单 commit 并含 signoff。
    • 评审通过后,维护人使用 Squash and merge 入库,DCO 状态必须为 ✅。

拓展思考

  1. 企业内网场景:若公司代码需同步到内部 GitLab,可在 .git/config 中增加 pushInsteadOf 映射,保证对外 PR 的 commit-id 与内部一致,满足审计。
  2. 大文件处理:Gunicorn 2025 年已启用 Git LFS 存储 tests/fixtures/large-body.bin,国内用户需配置 git lfs clone https://hub.gitclone.com/... 避免超时。
  3. 安全加固:建议把 DCO 签名与国产商用密码算法结合,使用 sm2 密钥做 GPG 签名,既合规又能通过 GitHub 验证。
  4. 自动化:可写 GitHub App 监听 pull_request.opened,自动评论 /ok-to-test 与 DCO 状态,减少维护人手工操作。