SuperAPI AI 工具集

gh-update-pr

编程与开发

查看项目

更新于 10-15 23:57

技能介绍

用途:当需要修改 GitHub Pull Request 的标题或正文时使用。由于 GitHub 弃用 Projects Classic,gh pr edit 会因 projectCards GraphQL 字段报错而失败;gh pr view 和 gh pr create 仍可正常使用,仅 gh pr edit 受影响。

主要能力:通过 gh api 调用 REST 端点 PATCH repos/{owner}/{repo}/pulls/{number} 来更新 PR 标题或正文,并用 jq --arg 传递 JSON 以避免 shell 注入。

使用方式:先获取当前 PR 上下文:gh pr view --json number,url,baseRefName。更新时只包含要修改的字段,未变更的字段应省略,避免用陈旧内容覆盖。示例命令:jq -n --arg title "..." --arg body "..." '{title: $title, body: $body}' | gh api repos/{owner}/{repo}/pulls/{number} -X PATCH --input - --jq '.html_url'。

验证:PATCH 后确认返回的是 PR 的 html_url 而非错误;再运行 gh pr view --json title,body 核对更新后的字段是否符合预期。

限制与常见错误:不要使用 gh pr edit 更新标题或正文;只改标题时不要在 JSON 中包含 body,反之亦然;需在带跟踪分支的 git 仓库内运行,否则 gh pr view 会失败,可显式传 --repo owner/repo;owner/repo/number 必须先从 gh pr view 获取,不要硬编码或假设。