create-pr
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseThe user likes the state of the code.
There are $ uncommitted changes.
The current branch is $.
The target branch is origin/main.
git status --porcelain | wc -l | tr -d ' 'git branch --show-current$
git rev-parse --abbrev-ref @{upstream} 2>/dev/null && echo "Upstream branch exists." || echo "There is no upstream branch yet."Existing PR: $
gh pr view --json number,title,url --jq '"#\(.number): \(.title) - \(.url)"' 2>/dev/null || echo "None"The user requested a PR.
Follow these exact steps:
用户对当前代码状态满意。
有$个未提交的更改。
当前分支为$。
目标分支是origin/main。
git status --porcelain | wc -l | tr -d ' 'git branch --show-current$
git rev-parse --abbrev-ref @{upstream} 2>/dev/null && echo "Upstream branch exists." || echo "There is no upstream branch yet."已存在的PR: $
gh pr view --json number,title,url --jq '"#\(.number): \(.title) - \(.url)"' 2>/dev/null || echo "None"用户请求创建PR。
请严格遵循以下步骤:
Phase 1: Review the code
阶段1:代码审查
- Review test coverage
- Check for silent failures
- Verify code comments are accurate
- Review any new types
- General code review
- 检查测试覆盖率
- 排查静默失败
- 验证代码注释的准确性
- 审查新增的类型定义
- 全面代码审查
Phase 2: Create/Update PR
阶段2:创建/更新PR
- Run to review uncommitted changes
git diff - Commit them. Follow any instructions the user gave you about writing commit messages.
- Push to origin.
- Use to review the full PR diff
git diff origin/main... - Check if a PR already exists for this branch:
- If PR exists:
- Draft/update the description in a temp file (e.g. ).
/tmp/pr-body.txt - Update the PR body using the non-deprecated script:
./.agents/skills/create-pr/scripts/pr-body-update.sh --file /tmp/pr-body.txt
- Re-fetch the body with to confirm it changed.
gh pr view --json body --jq .body
- Draft/update the description in a temp file (e.g.
- If no PR exists: Use to create a new PR. Keep the title under 80 characters and the description under five sentences.
gh pr create --base main
The PR description should summarize ALL commits in the PR, not just the latest changes.
- 运行查看未提交的更改
git diff - 提交更改。遵循用户关于编写提交信息的任何指示。
- 推送到origin。
- 使用查看PR的完整差异
git diff origin/main... - 检查当前分支是否已有对应的PR:
- 若PR已存在:
- 在临时文件(如)中草拟/更新PR描述。
/tmp/pr-body.txt - 使用非废弃脚本更新PR内容:
./.agents/skills/create-pr/scripts/pr-body-update.sh --file /tmp/pr-body.txt
- 运行重新获取PR内容以确认已更改。
gh pr view --json body --jq .body
- 在临时文件(如
- 若PR不存在:使用创建新PR。标题长度控制在80字符以内,描述不超过五句话。
gh pr create --base main
PR描述应总结PR中的所有提交,而非仅最新更改。
Phase 3: Monitor CI and Address Issues
阶段3:监控CI并处理问题
Note: Keep commands CI-safe and avoid interactive prompts. Ensure or is set in CI.
ghGH_TOKENGITHUB_TOKEN- Watch CI status and feedback using the polling script (instead of running in a loop):
gh
- Run (polls every 30s for 10 mins).
./.agents/skills/create-pr/scripts/poll-pr.sh --triage-on-change --exit-when-green - If checks fail, use or
gh pr checksto find the failing run id, then:gh run list- Fetch the failed check logs using
gh run view <run-id> --log-failed - Analyze the failure and fix the issue
- Commit and push the fix
- Continue polling until all checks pass
- Fetch the failed check logs using
- Check for merge conflicts:
- Run
git fetch origin main && git merge origin/main - If conflicts exist, resolve them sensibly
- Commit the merge resolution and push
- Use the polling script output to notice new reviews and comments (avoid direct polling via ):
gh
- If you need a full snapshot, run once.
./.agents/skills/create-pr/scripts/triage-pr.sh - If you need full context after the script reports a new item, fetch details once with or
gh pr view --comments.gh api ... - Address feedback:
- For bot reviews, read the review body and any inline comments carefully
- Address comments that are clearly actionable (bug fixes, typos, simple improvements)
- Skip comments that require design decisions or user input
- For addressed feedback, commit fixes with a message referencing the review/comment
注意:确保命令符合CI安全要求,避免交互式提示。确保CI环境中已设置或。
ghGH_TOKENGITHUB_TOKEN- 使用轮询脚本监控CI状态和反馈(而非循环运行):
gh
- 运行(每30秒轮询一次,持续10分钟)。
./.agents/skills/create-pr/scripts/poll-pr.sh --triage-on-change --exit-when-green - 若检查失败,使用或
gh pr checks找到失败的运行ID,然后:gh run list- 使用获取失败检查的日志
gh run view <run-id> --log-failed - 分析失败原因并修复问题
- 提交并推送修复
- 继续轮询直至所有检查通过
- 使用
- 检查合并冲突:
- 运行
git fetch origin main && git merge origin/main - 若存在冲突,合理解决
- 提交合并解决方案并推送
- 通过轮询脚本的输出来发现新的评审和评论(避免直接通过轮询):
gh
- 若需要完整快照,运行一次。
./.agents/skills/create-pr/scripts/triage-pr.sh - 若脚本报告有新内容后需要完整上下文,使用或
gh pr view --comments获取一次详细信息。gh api ... - 处理反馈:
- 对于机器人评审,仔细阅读评审内容和所有行内评论
- 处理明确可执行的评论(如bug修复、拼写错误、简单改进)
- 跳过需要设计决策或用户输入的评论
- 对于已处理的反馈,提交修复时在信息中引用对应的评审/评论
Phase 4: Merge and Cleanup
阶段4:合并与清理
-
Once CI passes and the PR is approved, ask the user if they want to merge the PR.
-
If the user confirms, merge the PR:
- Use to squash-merge and delete the remote branch
gh pr merge --squash --delete-branch
- Use
-
After successful merge, check if we're in a git worktree:
- Run:
[ "$(git rev-parse --git-common-dir)" != "$(git rev-parse --git-dir)" ] - If in a worktree: Use the ask user question tool () to ask if they want to clean up the worktree. If yes, run
request_user_inputto remove the worktree and local branch, then switch back to the main worktree.wt remove --yes --force - If not in a worktree: Just switch back to main with
git checkout main && git pull
- Run:
-
当CI通过且PR获得批准后,询问用户是否要合并该PR。
-
若用户确认,合并PR:
- 使用进行Squash合并并删除远程分支
gh pr merge --squash --delete-branch
- 使用
-
合并成功后,检查是否处于git工作树中:
- 运行:
[ "$(git rev-parse --git-common-dir)" != "$(git rev-parse --git-dir)" ] - 若处于工作树中:使用用户输入请求工具()询问用户是否要清理工作树。若同意,运行
request_user_input删除工作树和本地分支,然后切换回主工作树。wt remove --yes --force - 若未处于工作树中:只需使用切换回main分支并拉取最新代码
git checkout main && git pull
- 运行:
Completion
完成
Report the final PR status to the user, including:
- PR URL
- CI status (passed/merged)
- Any unresolved review comments that need user attention
- Cleanup status (worktree removed or branch switched)
If any step fails in a way you cannot resolve, ask the user for help.
向用户报告最终的PR状态,包括:
- PR链接
- CI状态(已通过/已合并)
- 任何需要用户关注的未解决评审评论
- 清理状态(工作树已删除或已切换分支)
若任何步骤出现无法解决的失败,向用户寻求帮助。