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 (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)./wt:new
提交当前工作树中所有已暂存的变更,推送到远程仓库,并创建GitHub PR(或检测已存在的PR)。设计用于工作流编排器自动调用。
注意: 在草稿PR优先的工作流中(会预先创建草稿PR),该技能主要用于向已有的草稿PR执行增量提交+推送操作。它能优雅处理两种场景:存在已有PR(提示「已更新」)和无PR(创建新PR)。/wt:new
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.yamlParameters
参数
| Parameter | Required | Default | Description |
|---|---|---|---|
| Yes | — | Story identifier (e.g., |
| Yes | — | Human-readable story title for commit message and PR |
| No | — | Path to PROOF file for PR body summary |
| No | — | Path to EVIDENCE.yaml for AC checklist in PR body |
| 参数 | 必填 | 默认值 | 描述 |
|---|---|---|---|
| 是 | — | 故事标识符(例如: |
| 是 | — | 人类可读的故事标题,用于提交信息和PR |
| 否 | — | PROOF文件的路径,用于PR正文摘要 |
| 否 | — | EVIDENCE.yaml的路径,用于PR正文的验收标准检查清单 |
What It Does
功能说明
This slash command:
- Verifies the current directory is inside the story worktree
- Stages all changes in the worktree
- Creates a conventional commit
- Pushes the branch to the remote
- Creates a new GitHub PR or detects an existing one
- Reports the result with PR number and URL
这条斜杠命令会执行以下操作:
- 验证当前目录位于故事工作树内
- 暂存工作树中的所有变更
- 创建符合约定式提交规范的提交
- 将分支推送到远程仓库
- 创建新的GitHub PR或检测已存在的PR
- 返回包含PR编号和URL的结果
Workflow
工作流
-
Verify worktree context - Confirm current directory is insideworktree. If not, attempt to locate and cd into it.
tree/story/{STORY_ID} -
Stage all changes - Run. This is safe because worktrees are isolated per-story; there is no risk of staging unrelated work.
git add -A -
Check for changes to commit - Run. If no staged changes exist, skip commit and push steps, proceed directly to PR check (step 5).
git status --porcelain -
Commit changes - Create a conventional commit:bash
git commit -m "feat({STORY_ID}): {STORY_TITLE}" -
Push to remote - Push the branch and set upstream:bash
git push -u origin story/{STORY_ID} -
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 -
Create or report PR:If no PR exists: Create one:bash
gh pr create --title "{STORY_ID}: {STORY_TITLE}" --body "..." --base mainThe PR body is built from:- Summary extracted from PROOF file (if provided)
PROOF_PATH - AC checklist extracted from EVIDENCE.yaml (if provided)
EVIDENCE_PATH - Default body if neither artifact is available
If PR already exists: Report "updated with new commits" and capture the existing PR number/URL. - Summary extracted from PROOF file (if
-
验证工作树上下文 - 确认当前目录位于工作树内。如果不是,尝试定位并进入该目录。
tree/story/{STORY_ID} -
暂存所有变更 - 执行。该操作是安全的,因为工作树是按故事隔离的,不存在暂存无关工作的风险。
git add -A -
检查待提交的变更 - 执行。如果不存在已暂存的变更,跳过提交和推送步骤,直接进入PR检查步骤(第5步)。
git status --porcelain -
提交变更 - 创建约定式提交:bash
git commit -m "feat({STORY_ID}): {STORY_TITLE}" -
推送到远程仓库 - 推送分支并设置上游分支:bash
git push -u origin story/{STORY_ID} -
检查已存在的PR - 查询GitHub上该分支的开放PR:bash
gh pr list --head story/{STORY_ID} --state open --json number,url -
创建PR或返回已有PR信息:如果不存在PR:创建新PR:bash
gh pr create --title "{STORY_ID}: {STORY_TITLE}" --body "..." --base mainPR正文由以下内容组成:- 从PROOF文件提取的摘要(如果提供了)
PROOF_PATH - 从EVIDENCE.yaml提取的验收标准检查清单(如果提供了)
EVIDENCE_PATH - 如果以上两种产物都不存在则使用默认正文
如果PR已存在:提示「已通过新提交更新」并返回现有PR的编号/URL。 - 从PROOF文件提取的摘要(如果提供了
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 | updatedIf 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 | unchangedThis structured output allows the calling orchestrator to parse and for CHECKPOINT.yaml.
pr_numberpr_url执行完成后,始终返回如下内容:
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这种结构化输出允许调用方编排器解析和用于CHECKPOINT.yaml。
pr_numberpr_urlError Handling
错误处理
| Error | Action |
|---|---|
| Not in a worktree | ERROR: "Not inside story worktree. Run from tree/story/{STORY_ID}." |
| ERROR: "GitHub CLI (gh) is required. Install: https://cli.github.com" |
| No changes to commit | WARNING: 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 fails | ERROR: Report |
| Not authenticated | ERROR: "gh auth required. Run: gh auth login" |
| 错误 | 处理动作 |
|---|---|
| 不在工作树内 | 错误提示:"Not inside story worktree. Run from tree/story/{STORY_ID}." |
| 错误提示:"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 auth required. Run: gh auth login" |
Notes
注意事项
- Worktrees are isolated per-story, so is safe
git add -A - 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 CLI must be installed and authenticated
gh
- 工作树是按故事隔离的,因此是安全的
git add -A - 提交信息遵循约定式提交格式:
feat({STORY_ID}): {STORY_TITLE} - PR的目标分支始终是
main - 如果被多次调用(例如修复问题后),会推送新的提交并自动更新现有PR
- 必须安装并完成CLI的认证
gh