create-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
The user likes the state of the code.
There are $
git status --porcelain | wc -l | tr -d ' '
uncommitted changes. The current branch is $
git branch --show-current
. The target branch is origin/main.
$
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:
用户对当前代码状态满意。
有$
git status --porcelain | wc -l | tr -d ' '
个未提交的更改。 当前分支为$
git branch --show-current
。 目标分支是origin/main。
$
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:代码审查

  1. Review test coverage
  2. Check for silent failures
  3. Verify code comments are accurate
  4. Review any new types
  5. General code review
  1. 检查测试覆盖率
  2. 排查静默失败
  3. 验证代码注释的准确性
  4. 审查新增的类型定义
  5. 全面代码审查

Phase 2: Create/Update PR

阶段2:创建/更新PR

  1. Run
    git diff
    to review uncommitted changes
  2. Commit them. Follow any instructions the user gave you about writing commit messages.
  3. Push to origin.
  4. Use
    git diff origin/main...
    to review the full PR diff
  5. 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
      gh pr view --json body --jq .body
      to confirm it changed.
  • If no PR exists: Use
    gh pr create --base main
    to create a new PR. Keep the title under 80 characters and the description under five sentences.
The PR description should summarize ALL commits in the PR, not just the latest changes.
  1. 运行
    git diff
    查看未提交的更改
  2. 提交更改。遵循用户关于编写提交信息的任何指示。
  3. 推送到origin。
  4. 使用
    git diff origin/main...
    查看PR的完整差异
  5. 检查当前分支是否已有对应的PR:
  • 若PR已存在
    • 在临时文件(如
      /tmp/pr-body.txt
      )中草拟/更新PR描述。
    • 使用非废弃脚本更新PR内容:
      • ./.agents/skills/create-pr/scripts/pr-body-update.sh --file /tmp/pr-body.txt
    • 运行
      gh pr view --json body --jq .body
      重新获取PR内容以确认已更改。
  • 若PR不存在:使用
    gh pr create --base main
    创建新PR。标题长度控制在80字符以内,描述不超过五句话。
PR描述应总结PR中的所有提交,而非仅最新更改。

Phase 3: Monitor CI and Address Issues

阶段3:监控CI并处理问题

Note: Keep commands CI-safe and avoid interactive
gh
prompts. Ensure
GH_TOKEN
or
GITHUB_TOKEN
is set in CI.
  1. Watch CI status and feedback using the polling script (instead of running
    gh
    in a loop):
  • Run
    ./.agents/skills/create-pr/scripts/poll-pr.sh --triage-on-change --exit-when-green
    (polls every 30s for 10 mins).
  • If checks fail, use
    gh pr checks
    or
    gh run list
    to find the failing run id, then:
    • 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
  1. 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
  1. Use the polling script output to notice new reviews and comments (avoid direct polling via
    gh
    ):
  • If you need a full snapshot, run
    ./.agents/skills/create-pr/scripts/triage-pr.sh
    once.
  • If you need full context after the script reports a new item, fetch details once with
    gh pr view --comments
    or
    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安全要求,避免交互式
gh
提示。确保CI环境中已设置
GH_TOKEN
GITHUB_TOKEN
  1. 使用轮询脚本监控CI状态和反馈(而非循环运行
    gh
    ):
  • 运行
    ./.agents/skills/create-pr/scripts/poll-pr.sh --triage-on-change --exit-when-green
    (每30秒轮询一次,持续10分钟)。
  • 若检查失败,使用
    gh pr checks
    gh run list
    找到失败的运行ID,然后:
    • 使用
      gh run view <run-id> --log-failed
      获取失败检查的日志
    • 分析失败原因并修复问题
    • 提交并推送修复
    • 继续轮询直至所有检查通过
  1. 检查合并冲突:
  • 运行
    git fetch origin main && git merge origin/main
  • 若存在冲突,合理解决
  • 提交合并解决方案并推送
  1. 通过轮询脚本的输出来发现新的评审和评论(避免直接通过
    gh
    轮询):
  • 若需要完整快照,运行一次
    ./.agents/skills/create-pr/scripts/triage-pr.sh
  • 若脚本报告有新内容后需要完整上下文,使用
    gh pr view --comments
    gh api ...
    获取一次详细信息。
  • 处理反馈
    • 对于机器人评审,仔细阅读评审内容和所有行内评论
    • 处理明确可执行的评论(如bug修复、拼写错误、简单改进)
    • 跳过需要设计决策或用户输入的评论
    • 对于已处理的反馈,提交修复时在信息中引用对应的评审/评论

Phase 4: Merge and Cleanup

阶段4:合并与清理

  1. Once CI passes and the PR is approved, ask the user if they want to merge the PR.
  2. If the user confirms, merge the PR:
    • Use
      gh pr merge --squash --delete-branch
      to squash-merge and delete the remote branch
  3. 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 (
      request_user_input
      ) to ask if they want to clean up the worktree. If yes, run
      wt remove --yes --force
      to remove the worktree and local branch, then switch back to the main worktree.
    • If not in a worktree: Just switch back to main with
      git checkout main && git pull
  1. 当CI通过且PR获得批准后,询问用户是否要合并该PR。
  2. 若用户确认,合并PR:
    • 使用
      gh pr merge --squash --delete-branch
      进行Squash合并并删除远程分支
  3. 合并成功后,检查是否处于git工作树中:
    • 运行:
      [ "$(git rev-parse --git-common-dir)" != "$(git rev-parse --git-dir)" ]
    • 若处于工作树中:使用用户输入请求工具(
      request_user_input
      )询问用户是否要清理工作树。若同意,运行
      wt remove --yes --force
      删除工作树和本地分支,然后切换回主工作树。
    • 若未处于工作树中:只需使用
      git checkout main && git pull
      切换回main分支并拉取最新代码

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状态(已通过/已合并)
  • 任何需要用户关注的未解决评审评论
  • 清理状态(工作树已删除或已切换分支)
若任何步骤出现无法解决的失败,向用户寻求帮助。