create-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Pull Request

创建Pull Request

Create pull requests following the best engineering practices.
Requires: GitHub CLI (
gh
) authenticated and available.
遵循最佳工程实践创建Pull Request。
要求:已完成身份验证且可用的GitHub CLI(
gh
)。

Prerequisites

前置条件

Before creating a PR, ensure all changes are committed. If there are uncommitted changes, run the commit skill
skill({ name: "conventional-commit" })
first to commit them properly.
bash
undefined
在创建PR之前,请确保所有变更都已提交。如果存在未提交的变更,请先运行提交技能
skill({ name: "conventional-commit" })
以正确提交这些变更。
bash
undefined

Check for uncommitted changes

Check for uncommitted changes

git status --porcelain

If the output shows any uncommitted changes (modified, added, or untracked files that should be included), invoke the commit skill `skill({ name: "conventional-commit" })` before proceeding.
git status --porcelain

如果输出显示存在未提交的变更(应包含的已修改、已添加或未跟踪文件),请在继续之前调用提交技能 `skill({ name: "conventional-commit" })`。

Process

流程

Step 1: Verify Branch State

步骤1:验证分支状态

bash
undefined
bash
undefined

Detect the default branch

Detect the default branch

BASE=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
BASE=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')

Check current branch and status

Check current branch and status

git status git log $BASE..HEAD --oneline

Ensure:
- All changes are committed
- Branch is up to date with remote
- Changes are rebased on the base branch if needed
git status git log $BASE..HEAD --oneline

确保:
- 所有变更都已提交
- 分支与远程仓库保持同步
- 如有需要,将变更变基到基准分支上

Step 2: Analyze Changes

步骤2:分析变更

Review what will be included in the PR:
bash
undefined
查看将包含在PR中的所有内容:
bash
undefined

See all commits that will be in the PR

See all commits that will be in the PR

git log $BASE..HEAD
git log $BASE..HEAD

See the full diff

See the full diff

git diff $BASE...HEAD

Understand the scope and purpose of all changes before writing the description.
git diff $BASE...HEAD

在撰写描述之前,了解所有变更的范围和目的。

Step 3: Write the PR Description

步骤3:撰写PR描述

Use this structure for PR descriptions (ignoring any repository PR templates):
markdown
<brief description of what the PR does>

<why these changes are being made - the motivation>

<alternative approaches considered, if any>

<any additional context reviewers need>
Do NOT include:
  • "Test plan" sections
  • Checkbox lists of testing steps
  • Redundant summaries of the diff
Do include:
  • Clear explanation of what and why
  • Links to relevant issues or tickets (only if available)
  • Context that isn't obvious from the code
  • Notes on specific areas that need careful review
使用以下结构撰写PR描述(忽略仓库的PR模板):
markdown
<PR内容的简要描述>

<进行这些变更的原因——动机>

<已考虑的替代方案(如有)>

<评审人员需要的其他上下文信息>
请勿包含
  • “测试计划”部分
  • 测试步骤的复选框列表
  • 差异内容的冗余摘要
请务必包含
  • 清晰的“做了什么”和“为什么做”的解释
  • 相关问题或工单的链接(仅当可用时)
  • 代码中不明显的上下文信息
  • 需要重点评审的特定区域的说明

Step 4: Create the PR

步骤4:创建PR

bash
gh pr create --draft --title "<type>(<scope>): <description>" --body "
<description body here>
"
Title format follows commit conventions:
  • feat(scope): Add new feature
  • fix(scope): Fix the bug
  • refactor(scope): Refactor something
bash
gh pr create --draft --title "<type>(<scope>): <description>" --body "
<描述内容>
"
标题格式遵循提交规范:
  • feat(scope): Add new feature
  • fix(scope): Fix the bug
  • refactor(scope): Refactor something

PR Description Examples

PR描述示例

Feature PR

功能PR

markdown
Add Slack thread replies for alert notifications

When an alert is updated or resolved, we now post a reply to the original
Slack thread instead of creating a new message. This keeps related
notifications grouped and reduces channel noise.

Previously considered posting edits to the original message, but threading
better preserves the timeline of events and works when the original message
is older than Slack's edit window.
markdown
Add Slack thread replies for alert notifications

When an alert is updated or resolved, we now post a reply to the original
Slack thread instead of creating a new message. This keeps related
notifications grouped and reduces channel noise.

Previously considered posting edits to the original message, but threading
better preserves the timeline of events and works when the original message
is older than Slack's edit window.

Bug Fix PR

修复PR

markdown
Handle null response in user API endpoint

The user endpoint could return null for soft-deleted accounts, causing
dashboard crashes when accessing user properties. This adds a null check
and returns a proper 404 response.
markdown
Handle null response in user API endpoint

The user endpoint could return null for soft-deleted accounts, causing
dashboard crashes when accessing user properties. This adds a null check
and returns a proper 404 response.

Refactor PR

重构PR

markdown
Extract validation logic to shared module

Moves duplicate validation code from the alerts, issues, and projects
endpoints into a shared validator class. No behavior change.

This prepares for adding new validation rules without
duplicating logic across endpoints.
markdown
Extract validation logic to shared module

Moves duplicate validation code from the alerts, issues, and projects
endpoints into a shared validator class. No behavior change.

This prepares for adding new validation rules without
duplicating logic across endpoints.

Guidelines

指南

  • One PR per feature/fix - Don't bundle unrelated changes
  • Keep PRs reviewable - Smaller PRs get faster, better reviews
  • Explain the why - Code shows what; description explains why
  • Mark WIP early - Use draft PRs for early feedback
  • 每个功能/修复对应一个PR - 不要捆绑无关变更
  • 保持PR易于评审 - 更小的PR能获得更快、更优质的评审
  • 解释原因 - 代码展示“做了什么”;描述解释“为什么做”
  • 尽早标记为WIP - 使用草稿PR获取早期反馈

Editing Existing PRs

编辑现有PR

When updating a PR after creation, the skill automatically selects the best approach based on your GitHub CLI version:
  • gh 2.82.1+: Uses native
    gh pr edit
    (clean, full-featured)
  • gh < 2.82.1: Falls back to
    gh api
    (avoids Projects classic deprecation bug)
在创建PR后进行更新时,本技能会根据你的GitHub CLI版本自动选择最佳方式:
  • gh 2.82.1+:使用原生的
    gh pr edit
    (简洁、功能完整)
  • gh < 2.82.1:回退到
    gh api
    (避免Projects classic弃用bug)

Check Your Version

检查你的版本

bash
undefined
bash
undefined

Check GitHub CLI version

Check GitHub CLI version

gh --version
undefined
gh --version
undefined

Modern Approach (gh 2.82.1+)

现代方式(gh 2.82.1+)

bash
undefined
bash
undefined

Update PR description

Update PR description

gh pr edit PR_NUMBER --body "Updated description here"
gh pr edit PR_NUMBER --body "Updated description here"

Update PR title

Update PR title

gh pr edit PR_NUMBER --title "New Title here"
gh pr edit PR_NUMBER --title "New Title here"

Update both

Update both

gh pr edit PR_NUMBER --title "new: Title" --body "New description"
undefined
gh pr edit PR_NUMBER --title "new: Title" --body "New description"
undefined

Legacy Fallback (gh < 2.82.1)

旧版回退方式(gh < 2.82.1)

If
gh pr edit
fails with a "Projects (classic) is being deprecated" error, use the API directly:
bash
undefined
如果
gh pr edit
因“Projects (classic) is being deprecated”错误失败,请直接使用API:
bash
undefined

Update PR description

Update PR description

gh api -X PATCH repos/{owner}/{repo}/pulls/PR_NUMBER -f body=" Updated description here "
gh api -X PATCH repos/{owner}/{repo}/pulls/PR_NUMBER -f body=" Updated description here "

Update PR title

Update PR title

gh api -X PATCH repos/{owner}/{repo}/pulls/PR_NUMBER -f title='New Title here'
gh api -X PATCH repos/{owner}/{repo}/pulls/PR_NUMBER -f title='New Title here'

Update both

Update both

gh api -X PATCH repos/{owner}/{repo}/pulls/PR_NUMBER
-f title='new: Title'
-f body='New description'

**Note**: The Projects (classic) bug was fixed in gh 2.82.1 (October 2025). Upgrade with your package manager if you're on an older version.
gh api -X PATCH repos/{owner}/{repo}/pulls/PR_NUMBER
-f title='new: Title'
-f body='New description'

**注意**:Projects (classic)的bug已在gh 2.82.1版本(2025年10月)中修复。如果你使用的是旧版本,请通过包管理器升级。