cleanup-merged-branches
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDelete remote branches that belong to a merged PR. Destructive, so it runs as a dry-run first and never deletes without explicit confirmation.
删除对应已合并PR的远程分支。由于操作具有破坏性,因此会先以**试运行(dry-run)**模式运行,且必须经过明确确认才会执行删除操作。
Delete rule
删除规则
A branch is deletable iff all hold — encoded in , the single source of truth:
scripts/plan.sh- it still exists on the remote,
- it has a merged PR,
- it has no open PR,
- it is not protected.
Protected = the default branch + . Never delete these, even if a merged PR points at them. A branch with no PR, or only a closed-unmerged PR, is not deletable (it never "belongs to a merged PR"). Extend the protected set in inside , nowhere else.
stagingis_protected()scripts/plan.sh一个分支可被删除的前提是同时满足以下所有条件——这些规则编码在中,是唯一的判断依据:
scripts/plan.sh- 该分支仍存在于远程仓库,
- 该分支关联的PR已合并,
- 该分支没有处于开放状态的PR,
- 该分支不属于受保护分支。
受保护分支指默认分支 + 分支。即使这些分支关联的PR已合并,也绝不能删除它们。没有关联PR,或仅关联了未合并就关闭的PR的分支,不可被删除(因为它们不属于“对应已合并PR的分支”)。如需扩展受保护分支集合,请修改中的函数,不要在其他地方修改。
stagingscripts/plan.shis_protected()Steps
操作步骤
- Dry-run. Run (pass a remote name as
bash scripts/plan.shif not$1). It prints deletable branches asorigin, and deletes nothing. Done when you have the list. Empty output → report "nothing to clean up" and stop.<branch> #<pr> <title> - Show + confirm. Show the full list to the user and ask for explicit go. Do not delete on a vague reply — only on a clear yes. This gate is mandatory every run.
- Delete. For each confirmed branch: . Nothing outside the plan's list may be deleted.
git push origin --delete <branch> - Report. List what was deleted; note any push that failed.
- 试运行(Dry-run)。运行(如果远程仓库不是
bash scripts/plan.sh,可将远程名称作为origin参数传入)。它会以$1的格式列出可删除的分支,且不会执行任何删除操作。获取到列表后即可完成此步骤。若输出为空,则提示“无需要清理的内容”并终止流程。<分支名> #<PR编号> <PR标题> - 展示并确认。将完整列表展示给用户,并请求明确的执行许可。仅在得到明确的“同意”回复时才可执行删除,模糊的回复不能作为执行依据。每次运行都必须经过此确认环节。
- 执行删除。对每个确认删除的分支,执行命令:。绝不能删除不在试运行列表中的任何分支。
git push origin --delete <分支名> - 结果报告。列出已成功删除的分支;若有推送失败的情况,需特别说明。
Also: stale-open issues
额外说明:长期开放的议题
Closes #Nrebuild/v1gh issue close #N --reason completed --comment "merged via #<pr>"只有当PR合并到默认分支时,才会自动关闭对应的议题#N——如果PR合并到集成分支(例如),议题#N会一直处于开放状态。对于在此处清理的每个已合并PR,请检查其关联的议题:如果工作内容已合并到默认分支但议题仍处于开放状态,请执行手动关闭它。这种情况会导致已完成的议题被标记为开放,需要在此环节进行排查处理。
Closes #Nrebuild/v1gh issue close #N --reason completed --comment "merged via #<pr>"