SuperAPI AI 工具集

gh-search

编程与开发

查看项目

更新于 10-15 08:09

技能介绍

用途

gh-search 用于在命令行中通过 GitHub CLI 的 gh search 子命令搜索 GitHub 内容,包括 issues、Pull Request、仓库、代码和提交。其核心原则是:当查询中包含排除条件(以 - 开头的限定符)时,始终使用 -- 分隔符,防止 shell 将 - 前缀解释为命令标志。

主要能力

该技能提供各子命令的快速参考:

  • gh search issues:搜索 issues,加 --include-prs 可同时包含 PR;常用标志有 --label、--state、--author、--assignee。
  • gh search prs:仅搜索 Pull Request;常用标志有 --label、--state、--author、--draft、--merged。
  • gh search repos:搜索仓库;常用标志有 --language、--stars、--topic、--owner。
  • gh search code:搜索文件内的代码;常用标志有 --repo、--language、--filename。
  • gh search commits:搜索提交信息;常用标志有 --repo、--author、--committer。

使用方式

关键语法规则

  1. 排除条件需要 -- 标志

Unix/Linux/Mac:

gh search issues -- "bug -label:duplicate"

PowerShell:

gh --% search issues -- "bug -label:duplicate"

原因:没有 -- 时,- 前缀会被解释为命令标志;PowerShell 需要 --% 来停止解析。

  1. 引号规则

多词查询需要引号:

gh search issues "memory leak"

包含空格的完整查询应加引号:

gh search issues "bug label:urgent created:>2024-01-01"

限定符值含空格时需要内层引号:

gh search prs -- 'security label:"bug fix"'

  1. 限定符语法

内联限定符(写在搜索查询中):

gh search repos "react stars:>1000 language:typescript"

基于标志(作为独立标志使用):

gh search repos "react" --language typescript --stars ">1000"

两者可混用:

gh search issues "crash" --label bug created:>2024-01-01

常用限定符

比较运算符:

  • 、>=、<、<=:数值比较,如 stars:>100、comments:>=5

  • ..:范围,如 stars:10..50、created:2024-01-01..2024-12-31

特殊值:

  • @me:当前用户,如 author:@me、assignee:@me、owner:@me
  • 日期使用 ISO8601:created:>2024-01-01 或 created:2024-01-01..2024-12-31

字段限定搜索:

  • in:title:仅在标题中搜索
  • in:body:仅在正文中搜索
  • in:comments:仅在评论中搜索

排除:

  • -qualifier:value:排除,如 -label:bug、-language:javascript
  • NOT 关键字:仅用于单词,如 "hello NOT world"

示例

查找自己未标记 bug 的开放 issues:

gh search issues -- "is:open author:@me -label:bug"

查找近期更新且热门的 Python 机器学习仓库:

gh search repos "machine learning" --language python --stars ">1000" --updated ">2024-01-01"

查找带特定标签和文本的 PR:

gh search prs -- 'security label:"bug fix" created:>2024-01-01'

在组织仓库中搜索代码:

gh search code "TODO" --owner myorg --language javascript

常见错误

  • gh search issues -label:bug:-label 被解释为标志;修复:加 --,即 gh search issues -- "-label:bug"。
  • gh search repos machine learning:会搜索 "machine" OR "learning";修复:加引号 "machine learning"。
  • in:title 放在引号外:shell 会异常解释冒号;修复:包含在查询中 "crash in:title"。
  • 将 @ 与值混用:语法无效;修复:使用 @me 或用户名,不能同时用,author:@me 正确,author:@username 错误(去掉 @)。
  • PowerShell 未使用 --%:排除条件会导致解析中断;修复:在命令前加 gh --%。

输出选项

所有子命令均支持:

  • --limit <n>:最大结果数(默认 30,最大 1000)
  • --json <fields>:JSON 输出,便于脚本处理
  • --web:在浏览器中打开结果
  • --sort <field>:排序字段,如 comments、created、reactions、updated、stars 等
  • --order asc|desc:排序方向(默认 desc)

适用场景

适用于需要通过命令行高效搜索 GitHub 的开发者,尤其是需要构造带排除条件、多限定符、含空格或特殊字符的复杂查询,以及需要在不同平台(Unix/Linux/Mac 与 PowerShell)上正确执行搜索的场景。

限制

资料未提供该技能的安装方式、依赖要求、收费模式或平台支持范围等额外信息。