wt-commit-and-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

/wt:commit-and-pr - Commit, Push, and Create/Update PR

/wt:commit-and-pr - 提交、推送并创建/更新PR

Description

描述

Commits all staged changes in the current worktree, pushes to the remote, and creates a GitHub PR (or detects an existing one). Designed for automated use from workflow orchestrators.
Note: With the draft-PR-first workflow (
/wt:new
creates a draft PR upfront), this skill is primarily used for incremental commit+push operations to existing draft PRs. It gracefully handles both cases: existing PRs (reports "updated") and new PRs (creates one).
提交当前工作树中所有已暂存的变更,推送到远程仓库,并创建GitHub PR(或检测已存在的PR)。设计用于工作流编排器自动调用。
注意: 在草稿PR优先的工作流中(
/wt:new
会预先创建草稿PR),该技能主要用于向已有的草稿PR执行增量提交+推送操作。它能优雅处理两种场景:存在已有PR(提示「已更新」)和无PR(创建新PR)。

Usage

用法

/wt:commit-and-pr {STORY_ID} "{STORY_TITLE}"
/wt:commit-and-pr {STORY_ID} "{STORY_TITLE}" {PROOF_PATH} {EVIDENCE_PATH}
/wt:commit-and-pr {STORY_ID} "{STORY_TITLE}"
/wt:commit-and-pr {STORY_ID} "{STORY_TITLE}" {PROOF_PATH} {EVIDENCE_PATH}

Examples

示例

/wt:commit-and-pr WINT-1012 "Add worktree management"
/wt:commit-and-pr WINT-1012 "Add worktree management" _implementation/PROOF-WINT-1012.md _implementation/EVIDENCE.yaml
/wt:commit-and-pr WINT-1012 "Add worktree management"
/wt:commit-and-pr WINT-1012 "Add worktree management" _implementation/PROOF-WINT-1012.md _implementation/EVIDENCE.yaml

Parameters

参数

ParameterRequiredDefaultDescription
STORY_ID
YesStory identifier (e.g.,
WINT-1012
)
STORY_TITLE
YesHuman-readable story title for commit message and PR
PROOF_PATH
NoPath to PROOF file for PR body summary
EVIDENCE_PATH
NoPath to EVIDENCE.yaml for AC checklist in PR body
参数必填默认值描述
STORY_ID
故事标识符(例如:
WINT-1012
STORY_TITLE
人类可读的故事标题,用于提交信息和PR
PROOF_PATH
PROOF文件的路径,用于PR正文摘要
EVIDENCE_PATH
EVIDENCE.yaml的路径,用于PR正文的验收标准检查清单

What It Does

功能说明

This slash command:
  1. Verifies the current directory is inside the story worktree
  2. Stages all changes in the worktree
  3. Creates a conventional commit
  4. Pushes the branch to the remote
  5. Creates a new GitHub PR or detects an existing one
  6. Reports the result with PR number and URL
这条斜杠命令会执行以下操作:
  1. 验证当前目录位于故事工作树内
  2. 暂存工作树中的所有变更
  3. 创建符合约定式提交规范的提交
  4. 将分支推送到远程仓库
  5. 创建新的GitHub PR或检测已存在的PR
  6. 返回包含PR编号和URL的结果

Workflow

工作流

  1. Verify worktree context - Confirm current directory is inside
    tree/story/{STORY_ID}
    worktree. If not, attempt to locate and cd into it.
  2. Stage all changes - Run
    git add -A
    . This is safe because worktrees are isolated per-story; there is no risk of staging unrelated work.
  3. Check for changes to commit - Run
    git status --porcelain
    . If no staged changes exist, skip commit and push steps, proceed directly to PR check (step 5).
  4. Commit changes - Create a conventional commit:
    bash
    git commit -m "feat({STORY_ID}): {STORY_TITLE}"
  5. Push to remote - Push the branch and set upstream:
    bash
    git push -u origin story/{STORY_ID}
  6. Check for existing PR - Query GitHub for an open PR on this branch:
    bash
    gh pr list --head story/{STORY_ID} --state open --json number,url
  7. Create or report PR:
    If no PR exists: Create one:
    bash
    gh pr create --title "{STORY_ID}: {STORY_TITLE}" --body "..." --base main
    The PR body is built from:
    • Summary extracted from PROOF file (if
      PROOF_PATH
      provided)
    • AC checklist extracted from EVIDENCE.yaml (if
      EVIDENCE_PATH
      provided)
    • Default body if neither artifact is available
    If PR already exists: Report "updated with new commits" and capture the existing PR number/URL.
  1. 验证工作树上下文 - 确认当前目录位于
    tree/story/{STORY_ID}
    工作树内。如果不是,尝试定位并进入该目录。
  2. 暂存所有变更 - 执行
    git add -A
    。该操作是安全的,因为工作树是按故事隔离的,不存在暂存无关工作的风险。
  3. 检查待提交的变更 - 执行
    git status --porcelain
    。如果不存在已暂存的变更,跳过提交和推送步骤,直接进入PR检查步骤(第5步)。
  4. 提交变更 - 创建约定式提交:
    bash
    git commit -m "feat({STORY_ID}): {STORY_TITLE}"
  5. 推送到远程仓库 - 推送分支并设置上游分支:
    bash
    git push -u origin story/{STORY_ID}
  6. 检查已存在的PR - 查询GitHub上该分支的开放PR:
    bash
    gh pr list --head story/{STORY_ID} --state open --json number,url
  7. 创建PR或返回已有PR信息
    如果不存在PR:创建新PR:
    bash
    gh pr create --title "{STORY_ID}: {STORY_TITLE}" --body "..." --base main
    PR正文由以下内容组成:
    • 从PROOF文件提取的摘要(如果提供了
      PROOF_PATH
    • 从EVIDENCE.yaml提取的验收标准检查清单(如果提供了
      EVIDENCE_PATH
    • 如果以上两种产物都不存在则使用默认正文
    如果PR已存在:提示「已通过新提交更新」并返回现有PR的编号/URL。

Output

输出

After completion, always report:
COMMIT AND PR COMPLETE
  story_id: {STORY_ID}
  branch: story/{STORY_ID}
  commit: {short_sha}
  pr_number: {number}
  pr_url: {url}
  pr_action: created | updated
If no changes were committed (step 3 skip):
COMMIT AND PR COMPLETE
  story_id: {STORY_ID}
  branch: story/{STORY_ID}
  commit: skipped (no changes)
  pr_number: {number}
  pr_url: {url}
  pr_action: created | updated | unchanged
This structured output allows the calling orchestrator to parse
pr_number
and
pr_url
for CHECKPOINT.yaml.
执行完成后,始终返回如下内容:
COMMIT AND PR COMPLETE
  story_id: {STORY_ID}
  branch: story/{STORY_ID}
  commit: {short_sha}
  pr_number: {number}
  pr_url: {url}
  pr_action: created | updated
如果没有提交任何变更(跳过了第3步):
COMMIT AND PR COMPLETE
  story_id: {STORY_ID}
  branch: story/{STORY_ID}
  commit: skipped (no changes)
  pr_number: {number}
  pr_url: {url}
  pr_action: created | updated | unchanged
这种结构化输出允许调用方编排器解析
pr_number
pr_url
用于CHECKPOINT.yaml。

Error Handling

错误处理

ErrorAction
Not in a worktreeERROR: "Not inside story worktree. Run from tree/story/{STORY_ID}."
gh
CLI not found
ERROR: "GitHub CLI (gh) is required. Install: https://cli.github.com"
No changes to commitWARNING: Skip commit/push, still check/create PR
Push fails (no remote)ERROR: "Push failed. Check remote configuration."
Push fails (rejected)WARNING: "Push rejected. Try pulling first: git pull --rebase origin story/{STORY_ID}"
PR creation failsERROR: Report
gh
error message verbatim
Not authenticatedERROR: "gh auth required. Run: gh auth login"
错误处理动作
不在工作树内错误提示:"Not inside story worktree. Run from tree/story/{STORY_ID}."
gh
CLI 未找到
错误提示:"GitHub CLI (gh) is required. Install: https://cli.github.com"
没有待提交的变更警告:跳过提交/推送,仍会检查/创建PR
推送失败(无远程仓库)错误提示:"Push failed. Check remote configuration."
推送失败(被拒绝)警告:"Push rejected. Try pulling first: git pull --rebase origin story/{STORY_ID}"
PR创建失败错误提示:逐字返回
gh
的错误信息
未完成认证错误提示:"gh auth required. Run: gh auth login"

Notes

注意事项

  • Worktrees are isolated per-story, so
    git add -A
    is safe
  • The commit message follows conventional commit format:
    feat({STORY_ID}): {STORY_TITLE}
  • PR base branch is always
    main
  • If called multiple times (e.g., after fixes), new commits are pushed and the existing PR updates automatically
  • The
    gh
    CLI must be installed and authenticated
  • 工作树是按故事隔离的,因此
    git add -A
    是安全的
  • 提交信息遵循约定式提交格式:
    feat({STORY_ID}): {STORY_TITLE}
  • PR的目标分支始终是
    main
  • 如果被多次调用(例如修复问题后),会推送新的提交并自动更新现有PR
  • 必须安装并完成
    gh
    CLI的认证