SuperAPI AI 工具集

gh-search-repos

编程与开发

查看项目

更新于 10-15 11:25

技能介绍

用途

gh-search-repos 是一个围绕 GitHub CLI 命令 gh search repos 的技能,用于在 GitHub 上搜索仓库。当需要按流行度、编程语言、主题、许可证、归档状态、所有者等条件查找仓库时,可以使用该技能提供的语法与示例。

主要能力

该技能覆盖 gh search repos [<query>] [flags] 的用法,支持以下筛选维度:

  • 仓库属性:--language(编程语言)、--topic(主题)、--license(许可证)、--archived(归档状态)、--owner(所有者)、--visibility(可见性:public、private、internal)。
  • 流行度指标:--stars(星标数)、--forks(复刻数)、--followers(关注者数)、--size(大小,单位 KB)。
  • 议题数量:--good-first-issues(good first issue 标签数量)、--help-wanted-issues(help wanted 标签数量)。
  • 日期筛选:--created(创建日期)、--updated(最后更新日期)。
  • 搜索范围:--match(在 name、description、readme 中搜索)、--include-forks(false、true、only)。
  • 输出与排序:-L, --limit(最大结果数,默认 30)、--sort(按 stars、forks、updated 等排序)、--order(asc 或 desc)、--json(JSON 输出)、-w, --web(在浏览器中打开)。

JSON 输出字段包括:createdAt、defaultBranch、description、forksCount、fullName、hasDownloads、hasIssues、hasPages、hasProjects、hasWiki、homepage、id、isArchived、isDisabled、isFork、isPrivate、language、license、name、openIssuesCount、owner、pushedAt、size、stargazersCount、updatedAt、url、visibility、watchersCount。

使用方式

基本语法:

gh search repos [<query>] [flags]

标志语法(用于正向筛选):

gh search repos "cli" --language go --stars ">100"

查询语法配合 --(排除时必须使用):

gh search repos -- "cli -language:javascript -archived:true"

关键规则:

  • 排除(否定)查询必须使用 -- 分隔符,并采用 -qualifier:value 格式,整个查询字符串需加引号。
  • 不要在同一条命令中混用标志语法与查询语法。
  • 比较运算符包括 >、>=、<、<=、..(范围)。
  • 比较运算符和范围需要加引号,例如 --stars ">1000"、--stars "100..500"。
  • 多词搜索需要加引号,例如 "machine learning"。
  • PowerShell 中使用排除时需加 --%,例如 gh --% search repos -- "cli -language:javascript"。

常见示例:

  • 查找热门 Python 仓库:gh search repos "data science" --language python --stars ">5000"
  • 查找有 good first issue 的仓库:gh search repos --language javascript --good-first-issues ">=10"
  • 查找最近更新的仓库:gh search repos "react" --updated ">2024-01-01" --stars ">100"
  • 按主题查找:gh search repos --topic machine-learning --language python
  • 按许可证查找:gh search repos "web framework" --license mit,apache-2.0
  • 排除归档仓库:gh search repos "cli tool" --archived false
  • 按组织查找:gh search repos --owner microsoft --visibility public
  • 排除复刻:gh search repos "starter" --include-forks false
  • 仅查找复刻:gh search repos "template" --include-forks only
  • 星标范围:gh search repos "game engine" --stars "100..1000"
  • 排除特定语言:gh search repos -- "cli -language:go"
  • 仅在名称中搜索:gh search repos "awesome" --match name

适用场景

  • 按流行度(星标/复刻)查找仓库。
  • 按编程语言或主题搜索。
  • 查找带有 good first issue 的仓库。
  • 按许可证或归档状态筛选。
  • 在特定组织内或按所有者搜索。
  • 需要排除某些结果(必须使用 -- 分隔符)。

限制与注意事项

  • 标志语法不支持否定,例如 --language="NOT javascript" 或 --archived=-true 无效,应改用查询语法 -- "-language:javascript" 或 -- "-archived:true"。
  • 直接写 gh search repos cli -language:js 会把 -language 当作标志解析,必须使用 --。
  • NOT 关键字不生效,应使用 -。
  • 不能混用标志与查询限定符,例如 --stars ">100" "cli -language:js" 不可用,应全部使用查询语法:-- "cli stars:>100 -language:js"。
  • 比较运算符不加引号会被 shell 解释,必须加引号。
  • --archived 只接受布尔值 true 或 false。
  • 多词搜索不加引号会被分开搜索。
  • --owner 不能带 @,例如应写 --owner github。
  • PowerShell 中排除查询不加 --% 会出错。
  • 若 gh 命令未找到,可用 which gh 检查,安装说明见 https://cli.github.com/manual/installation;若未认证,可运行 gh auth login。

相关资源

  • GitHub 搜索语法:https://docs.github.com/search-github/searching-on-github/searching-for-repositories
  • 搜索其他资源:gh-search-code、gh-search-commits、gh-search-issues、gh-search-prs