SuperAPI AI 工具集

gh-search-prs

编程与开发

查看项目

更新于 10-15 10:25

技能介绍

用途

gh-search-prs 是一个 GitHub CLI 技能,用于跨多个仓库或组织搜索 GitHub 拉取请求(PR)。它基于 gh search prs 命令,提供 PR 专属的过滤语法,适合需要跨仓库、跨组织进行复杂检索的场景。

该技能明确区分两类命令:gh search prs 用于 GitHub 全局搜索(跨多个仓库或组织、搜索当前目录之外的特定仓库、使用带限定符的搜索查询语法);gh pr list 仅用于当前工作目录所在仓库,使用简单的标志过滤。当用户说“我的 PR”或“这里的 PR”时,应使用 gh pr list;当用户指定仓库/组织或需要跨仓库搜索时,才使用本技能。

主要能力

该技能提供以下类别的过滤标志:

  • PR 专属过滤:--draft(草稿)、--merged(已合并)、--merged-at <date>(合并日期)、-B/--base <string>(基础分支)、-H/--head <string>(头分支)、--review <string>(审查状态)、--review-requested <user>(请求审查人)、--reviewed-by <user>(审查人)、--checks <string>(CI 检查状态)。
  • 用户过滤:--author、--assignee、--mentions、--commenter、--team-mentions。
  • PR 属性:--label、--state(open 或 closed)、--milestone、--locked、--no-label。
  • 仓库过滤:--owner、-R/--repo、--language、--visibility、--archived。
  • 互动指标:--comments、--reactions、--interactions,支持比较运算符。
  • 日期过滤:--created、--updated、--closed。
  • 搜索范围:--match(title、body、comments)。
  • 输出与排序:-L/--limit(默认 30)、--sort、--order、--json、-w/--web。

JSON 输出字段包括:assignees、author、authorAssociation、body、closedAt、commentsCount、createdAt、id、isDraft、isLocked、isPullRequest、labels、number、repository、state、title、updatedAt、url。

使用方式

基本语法:gh search prs [<query>] [flags]

关键语法规则:

  1. 排除与否定必须使用查询语法并配合 -- 分隔符。正确写法:gh search prs -- "search-terms -qualifier:value"。错误写法包括:gh search prs "search-terms" --flag=-value、gh search prs "search-terms" --flag=!value、gh search prs --label=-WIP。
  2. 不要在同一条命令中混用标志语法和查询语法。简单正向过滤使用标志语法,如 gh search prs "refactor" --draft --state open;涉及排除或复杂布尔逻辑时,全部使用查询语法,如 gh search prs -- "refactor -label:wip -is:draft"。
  3. 特殊值:@me 表示当前认证用户。
  4. 审查状态值:none、required、approved、changes_requested。
  5. 检查状态值:pending、success、failure。
  6. 引号规则:多词搜索使用引号;带空格的标签需整体引用,如 gh search prs -- 'refactor label:"needs review"';比较运算符需加引号,如 --comments ">5"。
  7. PowerShell 中使用排除时需加 --%,如 gh --% search prs -- "refactor -label:wip"。
  8. 字段限定符:in:title、in:body、in:comments,例如 gh search prs "authentication in:title" --state open。
  9. 比较运算符:>、>=、<、<=、..(范围)。

常见用例包括:查找自己在全 GitHub 上的开放 PR(gh search prs --author @me --state open);查找组织中等待自己审查的 PR(gh search prs --review-requested @me --state open --owner kubernetes);查找特定仓库中的草稿 PR(gh search prs --draft --repo microsoft/vscode);查找某组织某日期范围内已合并的 PR(gh search prs --merged --merged-at "2024-01-01..2024-12-31" --owner golang);查找特定仓库中检查失败的 PR(gh search prs --checks failure --state open --repo cli/cli);查找已批准但未合并的 PR(gh search prs --review approved --state open --repo kubernetes/kubernetes);跨仓库排除特定标签(gh search prs -- "refactor -label:wip -label:draft" --owner myorg);查找跨多个仓库的陈旧 PR(gh search prs --state open --updated "<2024-01-01" --owner rust-lang)。

适用场景

适用于:跨多个仓库或组织搜索 PR;在特定仓库中搜索 PR;跨 GitHub 搜索(如组织内所有草稿 PR);需要搜索限定符的复杂查询(如 golang 仓库中评论数超过 10 的已批准 PR)。

不适用于:用户询问“此仓库中的 PR”或“我在这里的 PR”;未指定仓库/组织且上下文明确为当前仓库。这些情况应使用 gh pr list。

限制与注意事项

  • 标志语法不支持否定,排除必须使用查询语法加 -- 分隔符。
  • 不能混用标志语法与查询限定符。
  • NOT 关键字无效,应使用 - 前缀。
  • --review-requested 不支持 @username 形式,应使用 @me 或直接写用户名。
  • 比较运算符不加引号会被 shell 解释。
  • 带空格的标签值需正确引用。
  • --merged 与 --state open 同时使用会产生矛盾(已合并的 PR 属于 closed 状态)。
  • PowerShell 中排除语法需加 --%。
  • 若 gh 命令未安装,需先安装(安装说明见 https://cli.github.com/manual/installation);若未认证,需运行 gh auth login。

相关技能:gh-search-code、gh-search-commits、gh-search-issues、gh-search-repos。GitHub 搜索语法参考:https://docs.github.com/search-github/searching-on-github/searching-issues-and-pull-requests