用途:在 Windows 环境编辑 GitHub Pull Request 的标题、正文与可选评论;当需要更新 PR 元数据,或 GitHub API 因缺权限返回 404 时使用。
使用前准备:确定 owner、repo 与 PR 编号;若用 gh,先确认可用与已认证:gh --version 与 gh auth status。私有仓库的未认证 API 请求常返回 404,除非确定仓库或 PR 不存在,否则应将 404 视为“很可能未授权”。
方式 A(首选)GitHub CLI:用 stdin/body-file 避免字面 \n 问题。更新标题和正文:@'\n<markdown body>\n'@ | gh pr edit 111 --title "chore: ..." --body-file -;添加评论:@'\nSummary:\n- ...\n'@ | gh pr comment 111 --body-file -。
方式 B:GitHub REST API(PowerShell,无 gh)。1)获取令牌(不要打印):优先取 $env:GITHUB_TOKEN 或 $env:GH_TOKEN;也可复用 Git 凭据:$cred = "protocol=httpsnhost=github.comn`n" | git credential fill 与 $token = (($cred | Select-String -Pattern '^password=').Line).Substring(9)。不要 Write-Host $token,也不要记录 headers。2)构建最小 headers:@{ Authorization = "token $token"; 'User-Agent' = 'codex-cli'; Accept = 'application/vnd.github+json' }。3)可用 Get 请求 https://api.github.com/repos/<owner>/<repo> 校验认证,若返回 404,令牌可能缺访问权限。4)更新标题/正文:构造 payload 后 ConvertTo-Json -Depth 5,用 UTF-8 字节编码,再 PATCH https://api.github.com/repos/<owner>/<repo>/pulls/<number>,ContentType 为 application/json; charset=utf-8。5)添加 PR 评论(评论即 issue comments):POST https://api.github.com/repos/<owner>/<repo>/issues/<number>/comments,同样使用 UTF-8 字节与对应 ContentType。
推荐做法:使用随附脚本减少引号与编码错误:.codex/skills/github-pr-edit/scripts/patch_pr.ps1。
限制:专为 Windows 场景(PowerShell);需有效的 gh 认证或 GitHub 令牌;未授权或令牌权限不足时会返回 404;资料未提供收费、价格、平台兼容范围等更多信息。