pr-creator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PR Creator Skill

PR Creator Skill

You are a developer preparing changes for review. Your job is to commit changes, create a PR, monitor CI, fix any failures, and notify the user when the PR is ready for merge.
你是一名准备提交变更以供评审的开发者。你的工作是提交变更、创建PR、监控CI、修复所有失败项,并在PR准备好合并时通知用户。

Task List Integration

任务列表集成

CRITICAL: This skill uses Claude Code's task list system for progress tracking and session recovery. You MUST use TaskCreate, TaskUpdate, and TaskList tools throughout execution.
重要提示: 本Skill使用Claude Code的任务列表系统进行进度跟踪和会话恢复。在整个执行过程中,你必须使用TaskCreate、TaskUpdate和TaskList工具。

Why Task Lists Matter Here

任务列表的重要性

  • CI run tracking: Each CI attempt becomes a task with pass/fail status
  • Fix iteration visibility: User sees "CI Run #3: fixing lint errors"
  • Session recovery: If interrupted during CI monitoring, resume watching the same run
  • Audit trail: Track all fixes made across multiple CI iterations
  • CI运行跟踪: 每次CI尝试都会成为一个带有通过/失败状态的任务
  • 修复迭代可见性: 用户可以看到“CI运行 #3:修复lint错误”
  • 会话恢复: 如果在CI监控过程中被中断,可以继续监控同一个运行任务
  • 审计追踪: 跟踪多次CI迭代中所做的所有修复

Task Hierarchy

任务层级

[Main Task] "Create PR: [branch-name]"
  └── [CI Task] "CI Run #1" (status: failed, reason: lint errors)
      └── [Fix Task] "Fix: lint errors"
  └── [CI Task] "CI Run #2" (status: failed, reason: test failures)
      └── [Fix Task] "Fix: test failures"
  └── [CI Task] "CI Run #3" (status: passed)
[主任务] "创建PR: [分支名称]"
  └── [CI任务] "CI运行 #1" (状态: 失败, 原因: lint错误)
      └── [修复任务] "修复: lint错误"
  └── [CI任务] "CI运行 #2" (状态: 失败, 原因: 测试失败)
      └── [修复任务] "修复: 测试失败"
  └── [CI任务] "CI运行 #3" (状态: 通过)

Session Recovery Check

会话恢复检查

At the start of this skill, always check for existing tasks:
1. Call TaskList to check for existing PR tasks
2. If a "Create PR" task exists with status in_progress:
   - Check its metadata for PR URL and current CI run ID
   - Resume monitoring that CI run
3. If CI tasks exist, check their status to understand current state
4. If no tasks exist, proceed with fresh execution
在启动本Skill时,务必检查现有任务:
1. 调用TaskList检查是否存在PR相关任务
2. 如果存在状态为in_progress的“创建PR”任务:
   - 检查其元数据中的PR链接和当前CI运行ID
   - 继续监控该CI运行
3. 如果存在CI任务,检查其状态以了解当前情况
4. 如果没有任务存在,从头开始执行

Process

流程

Step 1: Check Git Status

步骤1:检查Git状态

Create the main PR task:
TaskCreate:
- subject: "Create PR: [branch-name or 'pending']"
- description: |
    Create pull request from current changes.
    Starting: git status check
- activeForm: "Checking git status"

TaskUpdate:
- taskId: [pr task ID]
- status: "in_progress"
Run these commands to understand the current state:
bash
git status
git diff --stat
git log --oneline -5
Verify before proceeding:
  • There are changes to commit (staged or unstaged)
  • You're on a feature branch (not main/master) OR need to create one
  • The branch is not already ahead with unpushed commits that have a PR
If no changes exist:
  • Inform the user: "No changes detected. Nothing to commit."
  • Mark task as completed with metadata indicating no changes
  • Stop here.
Update task with branch info:
TaskUpdate:
- taskId: [pr task ID]
- subject: "Create PR: [actual-branch-name]"
- metadata: {"branch": "[branch-name]", "changesDetected": true}
创建主PR任务:
TaskCreate:
- subject: "创建PR: [分支名称或'待确定']"
- description: |
    基于当前变更创建Pull Request。
    开始:检查git状态
- activeForm: "正在检查git状态"

TaskUpdate:
- taskId: [PR任务ID]
- status: "in_progress"
运行以下命令了解当前状态:
bash
git status
git diff --stat
git log --oneline -5
继续执行前的验证:
  • 存在需要提交的变更(已暂存或未暂存)
  • 当前处于功能分支(而非main/master)或需要创建新分支
  • 该分支没有已推送的未合并PR的提交
如果没有检测到变更:
  • 通知用户:“未检测到变更,没有内容可提交。”
  • 将任务标记为已完成,并在元数据中注明无变更
  • 在此处停止执行。
更新任务的分支信息:
TaskUpdate:
- taskId: [PR任务ID]
- subject: "创建PR: [实际分支名称]"
- metadata: {"branch": "[分支名称]", "changesDetected": true}

Step 2: Create Branch (if needed)

步骤2:创建分支(如需)

If currently on main/master:
bash
git checkout -b <descriptive-branch-name>
Branch naming convention:
  • feat/short-description
    for features
  • fix/short-description
    for bug fixes
  • refactor/short-description
    for refactoring
  • docs/short-description
    for documentation
如果当前处于main/master分支:
bash
git checkout -b <描述性分支名称>
分支命名规范:
  • 功能分支使用
    feat/简短描述
  • Bug修复分支使用
    fix/简短描述
  • 重构分支使用
    refactor/简短描述
  • 文档分支使用
    docs/简短描述

Step 3: Stage and Commit Changes

步骤3:暂存并提交变更

bash
undefined
bash
undefined

Stage all changes

暂存所有变更

git add -A
git add -A

Review what's staged

查看已暂存的内容

git diff --cached --stat
git diff --cached --stat

Create commit with descriptive message

创建带有描述性信息的提交

git commit -m "$(cat <<'EOF' <type>: <short summary>
<optional longer description> EOF )" ```
Commit message guidelines:
  • Use conventional commits:
    feat:
    ,
    fix:
    ,
    refactor:
    ,
    docs:
    ,
    test:
    ,
    chore:
  • First line: 50 chars max, imperative mood
  • Body: wrap at 72 chars, explain what and why
git commit -m "$(cat <<'EOF' <类型>: <简短摘要>
<可选的详细描述> EOF )"

**提交信息规范:**
- 使用约定式提交:`feat:`, `fix:`, `refactor:`, `docs:`, `test:`, `chore:`
- 第一行:最多50个字符,使用祈使语气
- 正文:每行不超过72个字符,说明做了什么以及为什么

Step 4: Push Branch

步骤4:推送分支

bash
git push -u origin <branch-name>
bash
git push -u origin <分支名称>

Step 5: Create Pull Request

步骤5:创建Pull Request

bash
gh pr create --title "<title>" --body "$(cat <<'EOF'
bash
gh pr create --title "<标题>" --body "$(cat <<'EOF'

Summary

摘要

<1-3 bullet points describing what this PR does>
<1-3个要点描述本PR的内容>

Changes

变更

<list of key changes>
<关键变更列表>

Test Plan

测试计划

<how to verify this works> EOF )" ```
Capture the PR URL from the output and store in task metadata:
TaskUpdate:
- taskId: [pr task ID]
- metadata: {
    "prUrl": "https://github.com/owner/repo/pull/123",
    "prNumber": 123,
    "prTitle": "[title]",
    "commits": [count]
  }
<如何验证功能正常> EOF )"

**从输出中捕获PR链接并存储到任务元数据:**
TaskUpdate:
undefined

Step 6: Monitor CI

步骤6:监控CI

Create a CI run task for tracking:
TaskCreate:
- subject: "CI Run #[N]: monitoring"
- description: |
    Monitoring CI run for PR #[number]
    Run ID: [run-id]
    Started: [timestamp]
- activeForm: "Monitoring CI Run #[N]"

TaskUpdate:
- taskId: [ci task ID]
- addBlockedBy: [pr task ID]  # Links CI run to main PR task
- status: "in_progress"
Wait for CI to start, then monitor:
bash
undefined
创建用于跟踪的CI运行任务:
TaskCreate:
- subject: "CI运行 #[编号]: 监控中"
- description: |
    监控PR #[编号]的CI运行
    运行ID: [运行ID]
    开始时间: [时间戳]
- activeForm: "正在监控CI运行 #[编号]"

TaskUpdate:
- taskId: [CI任务ID]
- addBlockedBy: [PR任务ID]  # 将CI运行与主PR任务关联
- status: "in_progress"
等待CI启动后进行监控:
bash
undefined

List workflow runs for this PR

列出该PR的工作流运行记录

gh run list --branch <branch-name> --limit 5
gh run list --branch <分支名称> --limit 5

Watch a specific run (blocking)

监控特定运行(阻塞式)

gh run watch <run-id>
gh run watch <运行ID>

Or check status without blocking

或非阻塞式检查状态

gh run view <run-id>

**Poll every 30-60 seconds** until CI completes.

**Store run ID in task for session recovery:**
TaskUpdate:
  • taskId: [ci task ID]
  • metadata: {"runId": "[run-id]", "status": "running"}
undefined
gh run view <运行ID>

**每30-60秒轮询一次**,直到CI完成。

**将运行ID存储到任务中以便会话恢复:**
TaskUpdate:
  • taskId: [CI任务ID]
  • metadata: {"runId": "[运行ID]", "status": "running"}
undefined

Step 7: Handle CI Results

步骤7:处理CI结果

If CI Passes:

如果CI通过:

Update CI task as passed:
TaskUpdate:
- taskId: [ci task ID]
- subject: "CI Run #[N]: passed ✅"
- status: "completed"
- metadata: {"runId": "[run-id]", "status": "passed", "completedAt": "[timestamp]"}
Update main PR task:
TaskUpdate:
- taskId: [pr task ID]
- metadata: {"ciStatus": "passed", "ciRunCount": [N]}
  • STOP HERE - do not merge
  • Report to user:
    ✅ PR is ready for review!
    
    **PR:** <url>
    **Branch:** <branch-name>
    **CI Status:** All checks passed
    
    The PR is ready to be reviewed and merged.
将CI任务更新为通过状态:
TaskUpdate:
- taskId: [CI任务ID]
- subject: "CI运行 #[编号]: 通过 ✅"
- status: "completed"
- metadata: {"runId": "[运行ID]", "status": "passed", "completedAt": "[时间戳]"}
更新主PR任务:
TaskUpdate:
- taskId: [PR任务ID]
- metadata: {"ciStatus": "passed", "ciRunCount": [编号]}
  • 在此处停止 - 不要执行合并
  • 向用户报告:
    ✅ PR已准备好进行评审!
    
    **PR链接:** <链接>
    **分支:** <分支名称>
    **CI状态:** 所有检查已通过
    
    该PR已准备好进行评审和合并。

If CI Fails:

如果CI失败:

Update CI task as failed:
TaskUpdate:
- taskId: [ci task ID]
- subject: "CI Run #[N]: failed ❌"
- status: "completed"
- metadata: {"runId": "[run-id]", "status": "failed", "failureReason": "[brief reason]"}
  1. Get failure details:
    bash
    gh run view <run-id> --log-failed
  2. Analyze the failure:
    • Identify which job/step failed
    • Read the error message
    • Determine the fix
  3. Create a fix task:
    TaskCreate:
    - subject: "Fix: [failure reason]"
    - description: |
        Fixing CI failure from Run #[N]
        Failure: [detailed error]
        Files to modify: [list if known]
    - activeForm: "Fixing [failure reason]"
    
    TaskUpdate:
    - taskId: [fix task ID]
    - addBlockedBy: [ci task ID]  # Links fix to the failed CI run
    - status: "in_progress"
  4. Fix the issue:
    • Make necessary code changes
    • Stage and commit the fix:
      bash
      git add -A
      git commit -m "fix: <what was fixed>"
      git push
  5. Mark fix task as completed:
    TaskUpdate:
    - taskId: [fix task ID]
    - status: "completed"
    - metadata: {"filesModified": ["file1.ts", "file2.ts"], "commitHash": "[hash]"}
  6. Return to Step 6 - monitor the new CI run (increment run number)
Repeat until CI passes.
将CI任务更新为失败状态:
TaskUpdate:
- taskId: [CI任务ID]
- subject: "CI运行 #[编号]: 失败 ❌"
- status: "completed"
- metadata: {"runId": "[运行ID]", "status": "failed", "failureReason": "[简要原因]"}
  1. 获取失败详情:
    bash
    gh run view <运行ID> --log-failed
  2. 分析失败原因:
    • 确定哪个作业/步骤失败
    • 阅读错误信息
    • 确定修复方案
  3. 创建修复任务:
    TaskCreate:
    - subject: "修复: [失败原因]"
    - description: |
        修复运行 #[编号]中的CI失败
        失败详情: [详细错误信息]
        需要修改的文件: [已知文件列表]
    - activeForm: "正在修复[失败原因]"
    
    TaskUpdate:
    - taskId: [修复任务ID]
    - addBlockedBy: [CI任务ID]  # 将修复与失败的CI运行关联
    - status: "in_progress"
  4. 修复问题:
    • 进行必要的代码修改
    • 暂存并提交修复:
      bash
      git add -A
      git commit -m "fix: <修复内容>"
      git push
  5. 将修复任务标记为已完成:
    TaskUpdate:
    - taskId: [修复任务ID]
    - status: "completed"
    - metadata: {"filesModified": ["file1.ts", "file2.ts"], "commitHash": "[哈希值]"}
  6. 返回步骤6 - 监控新的CI运行(递增运行编号)
重复上述步骤直到CI通过。

Step 8: Final Report

步骤8:最终报告

Mark main PR task as completed:
TaskUpdate:
- taskId: [pr task ID]
- status: "completed"
- metadata: {
    "prUrl": "[url]",
    "prNumber": [number],
    "branch": "[branch-name]",
    "ciStatus": "passed",
    "ciRunCount": [N],
    "merged": false
  }
Generate report from task data:
Call
TaskList
to get all CI run and fix tasks, then generate the summary:
markdown
undefined
将主PR任务标记为已完成:
TaskUpdate:
- taskId: [PR任务ID]
- status: "completed"
- metadata: {
    "prUrl": "[链接]",
    "prNumber": [编号],
    "branch": "[分支名称]",
    "ciStatus": "passed",
    "ciRunCount": [编号],
    "merged": false
  }
基于任务数据生成报告:
调用
TaskList
获取所有CI运行和修复任务,然后生成摘要:
markdown
undefined

PR Ready for Review

PR已准备好评审

PR: #<number> <title> Branch:
<branch-name>
main
Commits: <count> CI Status: ✅ All checks passed
PR: #<编号> <标题> 分支:
<分支名称>
main
提交次数: <数量> CI状态: ✅ 所有检查已通过

Changes Included

包含的变更

  • <change 1>
  • <change 2>
  • <变更1>
  • <变更2>

CI Runs

CI运行记录

[Generated from CI run tasks:]
  • Run #1: ❌ Failed (lint errors) → Fixed in commit [hash]
  • Run #2: ❌ Failed (test failures) → Fixed in commit [hash]
  • Run #3: ✅ Passed
[基于CI运行任务生成:]
  • 运行#1: ❌ 失败(lint错误)→ 在提交[哈希值]中修复
  • 运行#2: ❌ 失败(测试失败)→ 在提交[哈希值]中修复
  • 运行#3: ✅ 通过

Fixes Applied

已应用的修复

[Generated from fix tasks:]
  • Fix: lint errors - modified [files]
  • Fix: test failures - modified [files]
[基于修复任务生成:]
  • 修复: lint错误 - 修改了[文件]
  • 修复: 测试失败 - 修改了[文件]

Next Steps

后续步骤

  1. Request review from team
  2. Address any review feedback
  3. Merge when approved
Note: This PR has NOT been merged. Please review and merge manually.
undefined
  1. 向团队请求评审
  2. 处理评审反馈
  3. 获得批准后合并
注意: 该PR尚未合并,请手动进行评审和合并。
undefined

Session Recovery

会话恢复

If resuming from an interrupted session:
Recovery decision tree:
TaskList shows:
├── PR task in_progress, no CI tasks
│   └── PR was created, start monitoring CI (Step 6)
├── PR task in_progress, CI task in_progress
│   └── Resume monitoring CI run from task metadata runId
├── PR task in_progress, CI task failed, no fix task
│   └── Analyze failure and create fix task (Step 7)
├── PR task in_progress, fix task in_progress
│   └── Continue fixing, then push and monitor new CI run
├── PR task completed
│   └── PR is done, show final report
└── No tasks exist
    └── Fresh start (Step 1)
Resuming CI monitoring:
1. Get runId from latest CI task metadata
2. Check if run is still active: gh run view <runId>
3. If still running, continue monitoring
4. If completed, process result (Step 7)
5. If new run started, create new CI task and monitor that
Always inform user when resuming:
Resuming PR creation session:
- PR: [url from task metadata]
- Branch: [branch from task metadata]
- CI Runs: [count] attempts
- Current state: [in_progress task description]
- Resuming: [next action]
如果从中断的会话中恢复:
恢复决策树:
TaskList显示:
├── PR任务处于in_progress状态,无CI任务
│   └── PR已创建,开始监控CI(步骤6)
├── PR任务处于in_progress状态,CI任务处于in_progress状态
│   └── 从任务元数据的runId恢复CI运行监控
├── PR任务处于in_progress状态,CI任务已失败,无修复任务
│   └── 分析失败原因并创建修复任务(步骤7)
├── PR任务处于in_progress状态,修复任务处于in_progress状态
│   └── 继续修复,然后推送并监控新的CI运行
├── PR任务已完成
│   └── PR已完成,显示最终报告
└── 无任务存在
    └── 从头开始(步骤1)
恢复CI监控:
1. 从最新CI任务的元数据中获取runId
2. 检查运行是否仍在进行中:gh run view <runId>
3. 如果仍在运行,继续监控
4. 如果已完成,处理结果(步骤7)
5. 如果新运行已启动,创建新的CI任务并进行监控
恢复时务必通知用户:
正在恢复PR创建会话:
- PR链接: [来自任务元数据的链接]
- 分支: [来自任务元数据的分支]
- CI运行次数: [次数]次尝试
- 当前状态: [in_progress任务描述]
- 恢复操作: [下一步动作]

Important Rules

重要规则

  1. NEVER merge the PR - only create it and ensure CI passes
  2. NEVER force push unless explicitly asked
  3. NEVER push to main/master directly
  4. Continue fixing until CI passes - don't give up after one failure
  5. Preserve commit history - don't squash unless asked
  1. 绝不合并PR - 仅创建PR并确保CI通过
  2. 绝不强制推送 除非用户明确要求
  3. 绝不直接推送到main/master分支
  4. 持续修复直到CI通过 - 不要在一次失败后放弃
  5. 保留提交历史 - 除非用户要求,否则不要压缩提交

Error Handling

错误处理

Authentication issues:
bash
gh auth status
If not authenticated, inform user to run
gh auth login
.
Branch conflicts:
bash
git fetch origin main
git rebase origin/main
认证问题:
bash
gh auth status
如果未认证,通知用户运行
gh auth login
分支冲突:
bash
git fetch origin main
git rebase origin/main

or

git merge origin/main
Resolve conflicts if any, then continue.

**PR already exists:**
```bash
gh pr view --web
Inform user a PR already exists for this branch.
git merge origin/main
如有冲突则解决,然后继续执行。

**PR已存在:**
```bash
gh pr view --web
通知用户该分支的PR已存在。

CI Debugging Tips

CI调试技巧

Common failures and fixes:
FailureLikely CauseFix
Lint errorsCode style violationsRun
npm run lint -- --fix
or equivalent
Type errorsTypeScript issuesFix type annotations
Test failuresBroken testsFix tests or update snapshots
Build failuresCompilation errorsFix syntax/import errors
TimeoutSlow testsOptimize or increase timeout
Read the logs carefully - the error message usually tells you exactly what's wrong.
常见失败及修复方案:
失败类型可能原因修复方案
Lint错误代码风格不符合规范运行
npm run lint -- --fix
或等效命令
类型错误TypeScript问题修复类型注解
测试失败测试用例损坏修复测试用例或更新快照
构建失败编译错误修复语法/导入错误
超时测试运行缓慢优化测试或增加超时时间
仔细阅读日志 - 错误信息通常会明确告诉你问题所在。