GitHub CLI

通过 gh 命令行工具管理 GitHub 仓库、PR、Issue 和 CI 流水线。

已扫描
适合谁
开发人员、团队技术负责人
不适合谁
仅需本地 Git 操作的用户、非 GitHub 平台使用者
国内可用性
需网络配置。可能需要网络配置或第三方服务可访问。
安装难度
新手友好(★☆☆)。基于终端操作、依赖、API Key 和本地环境要求的初步判断。

安装与下载

openclaw skills install @chuangyinbot-boop/cool-github-cli

Skill 说明

命令、参数、文件名以原文为准

GitHub Skill

使用 gh CLI 与 GitHub 仓库、问题、拉取请求(PR)和 CI 进行交互。

何时使用

请使用此技能当:

  • 检查拉取请求的状态、评审意见或合并就绪情况
  • 查看 CI/工作流运行状态和日志
  • 创建、关闭或对问题进行评论
  • 创建或合并拉取请求
  • 查询 GitHub API 获取仓库数据
  • 列出仓库、发布版本或协作者

何时不要使用

不要使用此技能当:

  • 执行本地 git 操作(提交、推送、拉取、分支)→ 直接使用 git
  • 非 GitHub 仓库(GitLab、Bitbucket、自托管)→ 使用不同的 CLI 工具
  • 克隆仓库 → 使用 git clone
  • 审查实际代码变更 → 使用 coding-agent 技能
  • 复杂的多文件差异 → 使用 coding-agent 或直接读取文件

设置

# 认证(一次性)
gh auth login

# 验证
gh auth status

常用命令

拉取请求(PR)

# 列出 PR
gh pr list --repo owner/repo

# 检查 CI 状态
gh pr checks 55 --repo owner/repo

# 查看 PR 详情
gh pr view 55 --repo owner/repo

# 创建 PR
gh pr create --title "feat: add feature" --body "Description"

# 合并 PR
gh pr merge 55 --squash --repo owner/repo

问题(Issues)

# 列出问题
gh issue list --repo owner/repo --state open

# 创建问题
gh issue create --title "Bug: something broken" --body "Details..."

# 关闭问题
gh issue close 42 --repo owner/repo

CI/工作流运行

# 列出最近的运行
gh run list --repo owner/repo --limit 10

# 查看特定运行
gh run view <run-id> --repo owner/repo

# 仅查看失败步骤的日志
gh run view <run-id> --repo owner/repo --log-failed

# 重新运行失败的任务
gh run rerun <run-id> --failed --repo owner/repo

API 查询

# 获取指定 PR 的特定字段
gh api repos/owner/repo/pulls/55 --jq '.title, .state, .user.login'

# 列出所有标签
gh api repos/owner/repo/labels --jq '.[].name'

# 获取仓库统计信息
gh api repos/owner/repo --jq '{stars: .stargazers_count, forks: .forks_count}'

JSON 输出

大多数命令支持 --json 以获取结构化输出,并配合 --jq 进行过滤:

gh issue list --repo owner/repo --json number,title --jq '.[] | "\(.number): \(.title)"'
gh pr list --json number,title,state,mergeable --jq '.[] | select(.mergeable == "MERGEABLE")'

模板

PR 审查摘要

# 获取 PR 概览用于审查
PR=55 REPO=owner/repo
echo "## PR #$PR Summary"
gh pr view $PR --repo $REPO --json title,body,author,additions,deletions,changedFiles \
  --jq '"**\(.title)** by @\(.author.login)\n\n\(.body)\n\n📊 +\(.additions) -\(.deletions) across \(.changedFiles) files"'
gh pr checks $PR --repo $REPO

问题分类(Triage)

# 快速问题分类视图
gh issue list --repo owner/repo --state open --json number,title,labels,createdAt \
  --jq '.[] | "[\(.number)] \(.title) - \([.labels[].name] | join(", ")) (\(.createdAt[:10]))"'

注意事项

  • 当不在 git 项目目录中时,始终指定 --repo owner/repo
  • 可直接使用 URL:gh pr view https://github.com/owner/repo/pull/55
  • 存在速率限制;对于重复查询,可使用 gh api --cache 1h
CB
@chuangyinbot-boop

已收录 1 个 Skill

相关推荐