关于 pull-request-msg-with-gh
此技能根据当前会话的代码变更和对话内容生成 `PR_MESSAGE.md`,供需要整理拉取请求说明的开发者使用。它通过 GitHub 搜索确认关联议题,并要求验证提交格式和 Markdown。
主要功能
- 01分析会话内容与 Git 变更
- 02通过 GitHub 搜索识别议题
- 03生成 `PR_MESSAGE.md`
- 04将文件加入 `.gitignore`
- 05运行提交与 Markdown 校验
适用场景
- 01为当前开发会话撰写 PR 说明
- 02确认拉取请求应关联的 GitHub 议题
- 03校验 PR 消息格式和 Markdown
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ rshade/ agent-skills --skill pull-request-msg-with-gh安装后在 Claude Code 中输入/pull-request-msg-with-gh确认已加载。
附带文件evals/evals.jsonreferences/pr-message-format.md
详细介绍
Pull Request 消息生成器
生成一个 PR_MESSAGE.md 文件,总结当前会话中的工作。
需要使用 gh CLI 登录目标仓库。
前置条件检查
gh --version 2>/dev/null && gh auth status 2>/dev/null
如果未安装 gh,请停止并报告:
- 从 https://cli.github.com 安装
- 不能通过 npm 安装
gh - 安装后,运行
gh auth login进行身份验证
不得在没有可用且已通过身份验证的 gh CLI 时继续。
工作流
- 分析会话上下文 — 回顾当前会话中所做的更改。使用
git diff和git status检查已更改的文件,了解工作的完整范围;同时回顾对话历史。这两个来源都会为 PR 消息提供依据。 - 检测议题编号 — 使用下方的议题检测算法。如果用户表示没有关联议题,则完全省略
Closes #<issue-number>页脚。 - 确定提交类型 — 根据更改的性质确定(类型列表见
references/pr-message-format.md) - 编写 PR_MESSAGE.md — 使用
references/pr-message-format.md中的格式 - 添加到 .gitignore — 如果尚未添加,则将
PR_MESSAGE.md添加到其中 - 验证 — 运行 commitlint 和 markdownlint 检查
议题编号检测
必须通过搜索 GitHub 来确定议题编号,不得从分支名称中提取数字。
算法
# Step 1: Get branch name
BRANCH=$(git branch --show-current)
# Step 2: Extract keywords (strip leading numbers and hyphens)
# Example: "125-greenops-equivalencies" → "greenops equivalencies"
KEYWORDS=$(echo "$BRANCH" | sed 's/^[0-9]*-//' | tr '-' ' ')
# Step 3: Search GitHub issues
gh issue list --search "$KEYWORDS" --state all \
--json number,title --limit 5
评估规则
- 恰好有 1 个结果,且标题包含最多关键词 → 使用该结果
- 0 个结果 → 询问用户议题编号
- 2 个或更多结果 → 展示选项并请用户选择
- 匹配不明确 → 请用户确认
绝不可从以下内容提取议题编号
- 分支名称中的数字(例如,
125-不是议题 #125) - 规格文件夹名称(例如,
specs/125-xyz/) - Worktree 文件夹名称
这些都是内部标识符,不是 GitHub 议题编号。
关键规则
- 避免冗余 — 摘要必须补充提交主题之外的上下文
- 不得添加
## Commit Message章节 — 第一行就是提交消息 - 绝不修改
.markdownlint.json— 改用 CLI 标志 - 末尾换行符 — 文件必须以单个换行符结尾
- 存在歧义时询问 — 如果议题搜索返回 0 个、2 个或更多,或结果不明确,请询问用户
验证
如果当前上下文中提供了 commitlint 和 markdownlint 技能,请使用它们验证 PR_MESSAGE.md。否则,直接运行:
# Validate commit message format
cat PR_MESSAGE.md | npx commitlint
# Validate markdown (MD041 disabled — first line is commit subject,
# not heading)
npx markdownlint --disable MD041 -- PR_MESSAGE.md
如果技能和 npx 都不可用,则必须报错:
- 安装 commitlint:
npm install -g @commitlint/cli @commitlint/config-conventional - 安装 markdownlint:
npm install -g markdownlint-cli
不得悄悄跳过验证。
修复所有问题并重新验证,然后再报告成功。
评论
支持 Markdown