SuperAPI AI 工具集

github

编程与开发

查看项目

更新于 10-15 16:35

技能介绍

用途

GitHub Skill 提供基于官方 gh CLI 工具的 GitHub 集成能力,用于创建和管理 GitHub 的 issue、pull request、workflow 与仓库。当被要求打开 PR、合并 pull request、检查仓库等任务时可以使用该技能。

该技能通过一个 Python 包装脚本为读取/查看类操作生成 markdown 格式输出,便于代理消费;而动作类命令(创建、合并、关闭、评论)应直接使用 gh。

主要能力

  • Issue:列出、查看、创建、评论、关闭、编辑(如添加标签)。
  • Pull Request:列出、查看、创建、审查(批准)、合并(如 squash)、检出分支、查看 diff、查看 CI 状态。
  • Workflow 与 Actions:列出 workflow、触发 workflow、列出运行记录、查看运行详情、监视运行进度、下载产物、重跑失败任务。
  • 仓库:列出、查看、创建、克隆、fork。
  • 搜索:搜索仓库、issue、pull request、代码。
  • 高级用法:JSON 输出用于脚本处理、通过 gh api 访问 GitHub API、设置别名、配置管理。

使用方式

前置条件:安装 gh CLI(安装指南见官方文档)。

认证:

# Authenticate with GitHub
gh auth login

# Verify authentication
gh auth status

脚本路径解析:示例中的 SKILL_DIR 是包含已加载 SKILL.md 的目录。运行命令前需将其设置为该绝对路径;不要假设代理会自动设置该 shell 变量。若脚本路径包含空格,需加引号。

脚本用法:包装脚本(scripts/github.py)将输出格式化为 markdown。读取/查看操作使用它可获得代理可消费的输出;动作命令(创建、合并、关闭、评论)直接使用 gh。各命令的读/写分类见 permissions.md。

# Check gh CLI is installed and authenticated
$SKILL_DIR/scripts/github.py check

# Issues
$SKILL_DIR/scripts/github.py issues list --repo OWNER/REPO
$SKILL_DIR/scripts/github.py issues view 123 --repo OWNER/REPO

# Pull Requests
$SKILL_DIR/scripts/github.py prs list --repo OWNER/REPO
$SKILL_DIR/scripts/github.py prs view 456 --repo OWNER/REPO
$SKILL_DIR/scripts/github.py prs checks 456 --repo OWNER/REPO
$SKILL_DIR/scripts/github.py prs status --repo OWNER/REPO

# Workflow Runs
$SKILL_DIR/scripts/github.py runs list --repo OWNER/REPO
$SKILL_DIR/scripts/github.py runs view 12345 --repo OWNER/REPO

# Repositories
$SKILL_DIR/scripts/github.py repos list
$SKILL_DIR/scripts/github.py repos view OWNER/REPO

# Search
$SKILL_DIR/scripts/github.py search repos "machine learning"
$SKILL_DIR/scripts/github.py search issues "label:bug is:open"
$SKILL_DIR/scripts/github.py search prs "is:open review:required"

所有命令的列表类操作支持 --limit N(默认 30)。

动作命令直接使用 gh,例如:

gh issue list
gh issue view 123
gh issue create
gh issue comment 123
gh issue close 123
gh issue edit 123 --add-label bug

gh pr list
gh pr view 456
gh pr create
gh pr review 456 --approve
gh pr merge 456 --squash
gh pr checkout 456
gh pr diff 456
gh pr checks 456

gh workflow list
gh workflow run "CI"
gh run list
gh run view 123456
gh run watch 123456
gh run download 123456
gh run rerun 123456 --failed

gh repo list
gh repo view OWNER/REPO
gh repo create
gh repo clone OWNER/REPO
gh repo fork OWNER/REPO

gh search repos "machine learning"
gh search issues "is:open label:bug"
gh search prs "is:open"
gh search code "function auth"

高级用法包括 JSON 输出用于脚本处理、通过 gh api 访问 GitHub API、设置别名、配置管理。

适用场景

  • 日常 PR 审查:查看需要关注的 PR、审查特定 PR、查看 CI 状态、查看 diff、批准并验证审查状态。
  • 创建 issue 并关联 PR:创建 issue 后记录编号,再创建引用该编号的 PR 并验证关联。
  • 监控 CI 流水线:监视最新 workflow 运行、检查失败运行、重跑失败任务并验证。

限制

网络访问:GitHub 命令(gh 和 Python 包装脚本)需要到 GitHub API 和认证端点的出站 HTTPS,或配置的 GitHub Enterprise 主机。Git fetch/push 需要到仓库主机的 HTTPS 或 SSH。远程操作需要出站网络访问。若代理环境限制网络,需在首次远程命令前通过该环境的审批或网络控制获得访问权限,并复用已授予的授权。本地帮助和文件处理不需要网络访问。技能说明本身不授予网络权限。DNS、连接和超时失败应报告为网络错误;不要通过重置凭据来解决。若已批准的访问仍然失败,应停止并报告。认证和权限错误需要用户操作。

模型指引:该技能包装的是官方 CLI,使用快速、轻量的模型即可。

故障排查:检查认证(gh auth status)、重新认证(gh auth login)、启用调试日志(GH_DEBUG=1 gh issue list)、检查 gh 版本(gh --version)。

官方文档:GitHub CLI Manual(https://cli.github.com/manual/)、GitHub CLI Repository(https://github.com/cli/cli)、GitHub API Documentation(https://docs.github.com/en/rest)、GitHub Actions(https://docs.github.com/en/actions)。

快速开始:安装 brew install gh(或对应操作系统的等效方式);认证 gh auth login;验证 $SKILL_DIR/scripts/github.py check;读取 $SKILL_DIR/scripts/github.py issues list --repo OWNER/REPO;写入 gh issue create、gh pr create 等(直接使用 gh)。详细命令参考可使用 gh <command> --help 或访问 https://cli.github.com/manual/。