git-ship
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommit PR CI Merge
Commit PR CI Merge
Full commit-to-merge flow with CI bypassed via GitHub Actions API.
通过GitHub Actions API绕过CI的完整从提交到合并流程。
Workflow
工作流
1. Detect repo → 2. Disable workflows → 3. Branch → 4. Commit → 5. Push → 6. PR → 7. Merge → 8. Re-enable workflows → 9. Cleanup1. Detect repo → 2. Disable workflows → 3. Branch → 4. Commit → 5. Push → 6. PR → 7. Merge → 8. Re-enable workflows → 9. CleanupSteps
步骤
1. Detect Repository
1. 检测仓库
Extract owner and repo from git remote:
bash
gh repo view --json owner,name --jq '[.owner.login, .name] | @tsv'Store as and for all subsequent gh api calls.
OWNERREPO从git远程地址提取所有者和仓库名:
bash
gh repo view --json owner,name --jq '[.owner.login, .name] | @tsv'将结果存储为和,供后续所有gh api调用使用。
OWNERREPO2. List and Disable Workflows
2. 列出并禁用工作流
Get all active workflows:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows --jq '.workflows[] | select(.state=="active") | [.id, .name] | @tsv'Disable each PR-triggered workflow:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/disable -X PUTTrack disabled workflow IDs for re-enabling later. Only disable workflows that trigger on or events. If unsure, disable all active workflows.
pull_requestpush获取所有活跃工作流:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows --jq '.workflows[] | select(.state=="active") | [.id, .name] | @tsv'禁用每个由PR触发的工作流:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/disable -X PUT记录被禁用的工作流ID,方便后续重新启用。仅禁用触发事件为或的工作流。如果不确定,可禁用所有活跃工作流。
pull_requestpush3. Create Feature Branch
3. 创建功能分支
If on main/master, create a branch. Use skill conventions for branch naming:
/commitbash
git checkout -b chore/short-description如果当前在main/master分支,创建新分支。分支命名遵循技能的规范:
/commitbash
git checkout -b chore/short-description4. Commit
4. 提交
Use skill for message generation.
/commitSkill(skill="commit")使用技能生成提交信息。
/commitSkill(skill="commit")5. Push
5. 推送
bash
git push -u origin $(git branch --show-current)bash
git push -u origin $(git branch --show-current)6. Create PR
6. 创建PR
Use skill for PR creation. Add a note in the PR body that CI was skipped.
/pr-createSkill(skill="pr-create")使用技能创建PR,在PR正文中添加说明,告知本次提交跳过了CI。
/pr-createSkill(skill="pr-create")7. Merge via API
7. 通过API合并
First attempt: merge using the GitHub API with flag:
--adminbash
gh pr merge {PR_NUMBER} --squash --adminIf merge fails with review requirement error (HTTP 405 or "approving review is required"):
- Save current review protection settings:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews --jq '{dismiss_stale_reviews, require_code_owner_reviews, require_last_push_approval, required_approving_review_count}'- Temporarily remove review requirement:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X DELETE- Merge:
bash
gh pr merge {PR_NUMBER} --squash --admin- Restore review protection using saved settings (use with JSON to preserve boolean types):
--input -
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X PATCH --input - <<'EOF'
{saved settings JSON}
EOFCRITICAL: Always restore branch protection, even if the merge fails. Use the saved settings from step 1 to restore the exact original configuration.
首次尝试:使用带参数的GitHub API合并:
--adminbash
gh pr merge {PR_NUMBER} --squash --admin如果合并失败并提示审查要求错误(HTTP 405或“需要批准审查”):
- 保存当前的审查保护设置:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews --jq '{dismiss_stale_reviews, require_code_owner_reviews, require_last_push_approval, required_approving_review_count}'- 临时移除审查要求:
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X DELETE- 合并:
bash
gh pr merge {PR_NUMBER} --squash --admin- 使用保存的设置恢复审查保护(使用带JSON参数的保留布尔类型):
--input -
bash
gh api repos/{OWNER}/{REPO}/branches/main/protection/required_pull_request_reviews -X PATCH --input - <<'EOF'
{saved settings JSON}
EOF关键提示: 即使合并失败,也必须始终恢复分支保护。使用步骤1中保存的设置恢复完全一致的原始配置。
8. Re-enable Workflows
8. 重新启用工作流
Re-enable all previously disabled workflows:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/enable -X PUT重新启用所有之前被禁用的工作流:
bash
gh api repos/{OWNER}/{REPO}/actions/workflows/{ID}/enable -X PUT9. Local Cleanup
9. 本地清理
bash
git checkout main && git pull && git branch -d {BRANCH_NAME}bash
git checkout main && git pull && git branch -d {BRANCH_NAME}Safety
安全注意事项
- Never skip CI for code changes that affect behavior
- Always re-enable workflows, even if merge fails
- Track disabled workflow IDs to ensure none are left disabled
- Appropriate for: renames, typos, config changes, documentation
- Not appropriate for: feature code, security changes, dependency updates
- 永远不要对影响功能的代码变更跳过CI
- 即使合并失败,也要始终重新启用工作流
- 记录被禁用的工作流ID,确保没有遗漏的被禁用工作流
- 适用场景:重命名、拼写修正、配置变更、文档修改
- 不适用场景:功能代码、安全相关变更、依赖更新