create-mr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create MR

创建MR

Create a GitHub pull request from the current branch by reading the repository state, respecting any PR template, and verifying the created PR.
从当前分支创建GitHub拉取请求,过程中会读取仓库状态、遵循PR模板并验证已创建的PR。

Workflow

工作流程

1. Detect PR Template

1. 检测PR模板

Search for a PR template in this order:
  1. .github/PULL_REQUEST_TEMPLATE.md
  2. .github/PULL_REQUEST_TEMPLATE/*.md
    (pick the first match)
  3. PULL_REQUEST_TEMPLATE.md
  4. docs/PULL_REQUEST_TEMPLATE.md
If a template is found, read it and use it as the base structure for the PR body. Preserve all template sections and fill them from the actual changes.
If no template is found, use the default body format below.
按以下顺序搜索PR模板:
  1. .github/PULL_REQUEST_TEMPLATE.md
  2. .github/PULL_REQUEST_TEMPLATE/*.md
    (选取第一个匹配的文件)
  3. PULL_REQUEST_TEMPLATE.md
  4. docs/PULL_REQUEST_TEMPLATE.md
如果找到模板,读取并将其作为PR正文的基础结构。保留所有模板章节,并根据实际变更填充内容。
如果未找到模板,则使用下方的默认正文格式。

2. Gather Context

2. 收集上下文

Run these checks, parallelizing file reads and git commands where possible:
bash
git status
git diff --staged
git diff
git log --oneline -20
git remote -v
git branch --show-current
执行以下检查,尽可能并行化文件读取和git命令:
bash
git status
git diff --staged
git diff
git log --oneline -20
git remote -v
git branch --show-current

3. Analyze Changes

3. 分析变更

From the gathered context:
  1. Summarize commits and diffs into a coherent narrative.
  2. Identify the change type: feature, bugfix, refactor, docs, chore, or test.
  3. Note verification evidence already present in the branch.
从收集到的上下文信息中:
  1. 将提交记录和差异内容总结为连贯的说明。
  2. 识别变更类型:功能新增(feature)、bug修复(bugfix)、代码重构(refactor)、文档更新(docs)、日常维护(chore)或测试相关(test)。
  3. 记录分支中已有的验证证据。

4. Check Changeset Requirement

4. 检查变更集(Changesets)要求

Before pushing or creating the PR, check whether the repository uses Changesets:
bash
test -d .changeset && test -f .changeset/config.json
rg -n '"@changesets/cli"|changeset' package.json pnpm-lock.yaml package-lock.json yarn.lock 2>/dev/null
If Changesets is not configured, skip this step.
If Changesets is configured, inspect the staged, unstaged, and unpushed branch diff that will be included in the PR. When the diff changes a versioned package or adds a backward-compatible public capability, and no matching
.changeset/*.md
file is already included, use the
changeset
skill before pushing.
Do not duplicate package eligibility, package-name, or bump-selection logic here. Let the
changeset
skill derive package names, release impact, and validation commands from repository metadata and Changesets config.
Include any generated
.changeset/*.md
file in the branch before running
git push
and
gh pr create
.
在推送分支或创建PR之前,检查仓库是否使用Changesets:
bash
test -d .changeset && test -f .changeset/config.json
rg -n '"@changesets/cli"|changeset' package.json pnpm-lock.yaml package-lock.json yarn.lock 2>/dev/null
如果未配置Changesets,跳过此步骤。
如果已配置Changesets,检查将包含在PR中的暂存、未暂存和未推送的分支差异。当差异修改了版本化包或添加了向后兼容的公共功能,且未包含匹配的
.changeset/*.md
文件时,需在推送前使用
changeset
技能。
此处无需重复包适用性、包名称或版本升级选择逻辑。让
changeset
技能从仓库元数据和Changesets配置中推导包名称、发布影响和验证命令。
在执行
git push
gh pr create
之前,将生成的
.changeset/*.md
文件加入分支。

5. Generate PR Title and Body

5. 生成PR标题和正文

Title requirements:
  • 72 characters or fewer.
  • Imperative mood.
  • Conventional commit style:
    <type>(<scope>): <short description>
    .
Example:
text
feat(auth): add OAuth2 login flow
Default body when no template exists:
markdown
undefined
标题要求:
  • 长度不超过72个字符。
  • 使用祈使语气。
  • 符合规范提交格式:
    <type>(<scope>): <简短描述>
示例:
text
feat(auth): add OAuth2 login flow
未找到模板时的默认正文格式:
markdown
undefined

Summary

摘要

  • <1-3 bullets summarizing what this PR does>
  • <1-3条要点总结本PR的内容>

Changes

变更内容

  • <key change 1>
  • <key change 2>
  • <关键变更1>
  • <关键变更2>

Test Plan

测试计划

  • <how to verify these changes>
  • <如何验证这些变更>

Screenshots

截图

<before/after for visual changes, or omit if not applicable>
undefined
<视觉变更的前后对比图,若无则省略>
undefined

Create the Pull Request

创建拉取请求

Use GitHub CLI:
bash
gh pr create --title "<title>" --body "<body>"
If the body is large, write it to a temporary file and pass
--body-file
.
If the current branch has no remote tracking branch, push first:
bash
git push -u origin HEAD
Then retry
gh pr create
.
使用GitHub CLI:
bash
gh pr create --title "<title>" --body "<body>"
如果正文内容较长,可将其写入临时文件并使用
--body-file
参数传递。
如果当前分支没有远程跟踪分支,先推送分支:
bash
git push -u origin HEAD
然后重试
gh pr create

Verify

验证

After creation, run:
bash
gh pr view <number>
For machine-readable verification, prefer:
bash
gh pr view <number> --json number,title,url,state,headRefName,baseRefName
Report the PR URL to the user.
创建完成后,执行:
bash
gh pr view <number>
若需机器可读的验证结果,优先使用:
bash
gh pr view <number> --json number,title,url,state,headRefName,baseRefName
将PR的URL告知用户。

Common Mistakes

常见错误

MistakeFix
Ignoring a PR templateSearch all supported template locations first.
Writing a title from memoryBase the title on the actual diff and commits.
Claiming tests passed without evidencePut only verified commands in the test plan.
Omitting a required changesetCheck Changesets support and use the
changeset
skill before pushing release-impacting changes.
Forgetting to push the branchPush with
git push -u origin HEAD
, then create the PR.
错误修复方法
忽略PR模板先搜索所有支持的模板路径。
凭记忆编写标题根据实际的差异内容和提交记录生成标题。
无证据声称测试通过仅在测试计划中写入已验证的命令。
遗漏必填的changeset在推送影响发布的变更前,检查Changesets支持情况并使用
changeset
技能。
忘记推送分支使用
git push -u origin HEAD
推送分支,再创建PR。