关于 github-pr-edit
github-pr-edit 是一项用于在 Windows 上编辑 GitHub PR 标题、正文和评论的技能,面向维护 PR 内容的开发者。它优先使用已安装并完成认证的 gh,否则通过 PowerShell 调用 GitHub REST API,并提供辅助脚本以减少转义和编码问题。
主要功能
- 01编辑 PR 标题和正文
- 02为 PR 添加评论
- 03优先使用 gh 命令行
- 04可通过 PowerShell 调用 REST API
- 05提供辅助脚本处理编码与转义
适用场景
- 01更新 PR 的标题和描述
- 02向 PR 添加总结评论
- 03gh 不可用时通过 REST API 编辑 PR
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ yiyousiow000814/ xauusd-calendar-agent --skill github-pr-edit安装后在 Claude Code 中输入/github-pr-edit确认已加载。
附带文件scripts/patch_pr.ps1
详细介绍
GitHub PR 编辑(标题/正文/评论)
在 Windows 上编辑 PR 标题、正文和评论。优先使用 gh;否则使用 GitHub REST API。
开始之前
- 确认:
owner和repo(例如:yiyousiow000814/XAUUSD-Calendar-Agent)- PR 编号(例如:
111)
- 如果使用
gh,请确认其可用且已通过身份验证:
gh --version
gh auth status
- 如果仓库是私有的,未经身份验证的 GitHub API 请求通常会返回
404 Not Found。除非确定仓库/PR 不存在,否则应将404视为“可能未获授权”。
选项 A(首选):GitHub CLI(gh)
如果已安装 gh 且已通过身份验证:
# Update title and body (use stdin/body-file to avoid literal \n issues)
@'
<markdown body>
'@ | gh pr edit 111 --title "chore: ..." --body-file -
添加评论:
@'
Summary:
- ...
'@ | gh pr comment 111 --body-file -
选项 B:GitHub REST API(PowerShell,无需 gh)
1)获取身份验证令牌(不要打印)
首选来源(选择第一个可用项):
$env:GITHUB_TOKEN或$env:GH_TOKEN- 复用 Git 已有的凭据(如果之前使用 PAT 进行过身份验证,此方法有效):
$cred = "protocol=https`nhost=github.com`n`n" | git credential fill
$token = (($cred | Select-String -Pattern '^password=').Line).Substring(9)
不要执行 Write-Host $token,也不要记录请求头。
2)构建请求头(最少配置)
$headers = @{
Authorization = "token $token"
'User-Agent' = 'codex-cli'
Accept = 'application/vnd.github+json'
}
3)检查身份验证(出现 404 时很有用)
Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/<owner>/<repo>" -Headers $headers |
Select-Object full_name, private
如果此处返回 404,你的令牌可能没有访问权限。
4)更新 PR 标题/正文
使用 UTF-8 字节以确保编码可靠(中文文本、标点)。
$payload = @{
title = 'chore: ...'
body = @"
Summary:
- ...
"@
} | ConvertTo-Json -Depth 5
$bytes = [System.Text.Encoding]::UTF8.GetBytes($payload)
Invoke-RestMethod -Method Patch `
-Uri "https://api.github.com/repos/<owner>/<repo>/pulls/<number>" `
-Headers $headers `
-ContentType 'application/json; charset=utf-8' `
-Body $bytes
5)添加 PR 评论(可选)
PR 评论属于 issue 评论:
$payload = @{ body = "Summary:`n- ..." } | ConvertTo-Json -Depth 5
$bytes = [System.Text.Encoding]::UTF8.GetBytes($payload)
Invoke-RestMethod -Method Post `
-Uri "https://api.github.com/repos/<owner>/<repo>/issues/<number>/comments" `
-Headers $headers `
-ContentType 'application/json; charset=utf-8' `
-Body $bytes
确定性辅助脚本(推荐)
使用随附脚本,减少引号/编码错误:
.codex/skills/github-pr-edit/scripts/patch_pr.ps1
评论
支持 Markdown