Skip to content

repo: fix the helper that applies the governance files - #10

Merged
cadywang merged 2 commits into
mainfrom
repo/merge-settings
Oct 19, 2026
Merged

cadywang merged 2 commits into
mainfrom
repo/merge-settings

Conversation

@cadywang

Copy link
Copy Markdown
Owner

变更说明

起因是把 governance/ 里的设置真正应用到仓库时被 GitHub 拒了:

1. PATCH /repos/... 报 422 no_squash_merge_strategy
治理文件里还留着 squash_merge_commit_message / squash_merge_commit_title / merge_commit_title,
而 squash 已经关闭——GitHub 不允许给已关闭的合并策略设置这些字段,于是整个 PATCH 失败,
只有合并方式那几项在早先单独生效过。这正是「治理文件与线上漂移」的根源:脚本一跑就 422,
后面的字段一个都没落地。现在只发送当前启用且有值的字段(squash 开则发 squash 两项、
merge commit 开则发 merge_commit_title),治理文件也不再保留这三项。

2. -DryRun 会改名本地分支
git remote add/set-url 与 git branch -M main 写在 dry-run 判断之外:文档说 dry-run「只打印 API 调用」,
实际却会把当前分支(比如正在评审的那个)改名成 main。现在这两步只在真正推送时执行。

线上状态(本 PR 之外已单独对齐,供参考):main 的必需检查 6 个(含 PR gate)、
delete_branch_on_merge=true、只允许 Rebase and merge、topics/description 已按治理文件设置。

本 PR 的提交:

  • tools: keep a dry run from touching the local checkout
  • repo: stop sending squash settings GitHub rejects

变更类型

  • 缺陷修复(fix)
  • 构建、CI、打包(build / ci)
  • 仅文档(docs)

影响面清单

  • 文档 / 仓库治理文件

改动只涉及 governance/repository-settings.json、tools/create-github-repo.ps1、CHANGELOG.md;
agent/*、cli/*、tests/*、协议均未改动。

测试

守卫逻辑(直接从 tools/create-github-repo.ps1 抽出真实代码块跑,不是复刻):

squash off(治理文件现状)      -> 发送字段: []
squash on(含三个键)           -> 发送字段: [squash_merge_commit_message, squash_merge_commit_title]
merge commit on                 -> 发送字段: [merge_commit_title]

-DryRun 端到端(真实执行脚本):

POST /users/cadywang/repos  的 body 里已无 squash/merge 标题字段  ✅
PUT  /branches/main/protection 的 contexts 是 6 个(含 PR gate)    ✅
dry-run 前后:branch=repo/merge-settings(未被改名)                ✅

其余门禁:all .ps1 parse OK、python -m compileall 0、YAML+JSON 解析、
无 BOM/CR、git diff --check 干净、commit 规范 2/2、pr-gate 自测 18/18、commit 门禁自测 18/18。

  • 已在真实设备上验证(如适用),命令:bash tests/verify-live.sh <client>:<port>

设备与链路信息(涉及传输改动时必填):

项 值
client OS 不适用(未改动传输路径)
串口 / 波特率 不适用
设备 shell / 系统 不适用
可用工具(base64/awk/od/md5sum) 不适用

合并前清单

CI 强制逐条勾选(pr-gate):少一项就不能合并。

  • 本地 mock 自测已全部通过,输出贴在「测试」小节
  • 协议 / 传输行为有改动时,PROTOCOL.md 与 agent/*、cli/* 四个实现已同步更新
  • 代码与注释为英文,文档为中文
  • 文件为 UTF-8(无 BOM)+ LF
  • 未提交临时产物(.tmp-*/、*.log、__pycache__/)
  • 每个 commit 遵循内核规范:<subsystem>: 祈使句摘要、正文 72 列折行,并带 Signed-off-by:(git commit -s)
  • PR 标题遵循内核规范 <subsystem>: 祈使句摘要>(网页端 squash 会把它写成提交标题)
  • 已更新 CHANGELOG.md(如面向用户的行为有变化)
  • 已阅读并遵守 SECURITY.md(不引入默认对外暴露、无鉴权的行为)

关联 Issue

无独立 Issue。起因:对齐线上仓库设置时 PATCH 被 422 拒掉,顺带发现 -DryRun 会改本地分支。

Applying governance/repository-settings.json to a repository whose squash
strategy is off failed with 422 no_squash_merge_strategy: the file still
carried squash_merge_commit_message, squash_merge_commit_title and
merge_commit_title, and GitHub refuses to set those for a strategy that is
disabled. That is how this repository's live settings drifted from the
file that is supposed to describe them -- the merge methods were the only
part of the payload that ever landed.

Send the three fields only when the matching strategy is enabled and the
file still lists them, and drop them from the file (they describe a
strategy this repository no longer offers). A squash-enabled fork can put
them back and the script will send them again; the guard is what makes
either choice work.

Verified by running the guard against the committed file (no fields sent),
a synthetic squash-enabled file (both squash fields sent) and a
merge-commit-enabled file (merge_commit_title sent).

Signed-off-by: cadywang <cadywang@users.noreply.github.com>
-DryRun promises to print the API calls without touching GitHub, but the
remote add/set-url and the "git branch -M main" ran before that guard: a
dry run renamed whatever branch the maintainer happened to be on -- the
branch he was reviewing, not the one being published.

Move both into the branch that actually pushes. A dry run now reads the
settings files, prints the calls and stops.

Signed-off-by: cadywang <cadywang@users.noreply.github.com>
@cadywang
cadywang merged commit 9913987 into main Oct 19, 2026
6 checks passed
@cadywang
cadywang deleted the repo/merge-settings branch October 19, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant