用途
本技能通过 gh CLI 与 GitHub 仓库、issues、PR 和 CI 进行交互。适用于需要从命令行操作 GitHub 平台数据的场景,例如仓库协作、持续集成状态跟踪和 API 数据查询。
主要能力
- Pull Requests:列出 PR、检查 CI 状态、查看 PR 详情、创建 PR、合并 PR。
- Issues:列出 issue、创建 issue、关闭 issue。
- CI/Workflow Runs:列出近期运行、查看特定运行、仅查看失败步骤日志、重新运行失败的作业。
- API 查询:获取 PR 的特定字段、列出所有标签、获取仓库统计数据。
- JSON 输出:多数命令支持
--json结构化输出,并可用--jq进行过滤。
使用方式
首先进行一次认证并验证:
# Authenticate (one-time)
gh auth login
# Verify
gh auth status
常用命令示例:
Pull Requests:
# List PRs
gh pr list --repo owner/repo
# Check CI status
gh pr checks 55 --repo owner/repo
# View PR details
gh pr view 55 --repo owner/repo
# Create PR
gh pr create --title "feat: add feature" --body "Description"
# Merge PR
gh pr merge 55 --squash --repo owner/repo
Issues:
# List issues
gh issue list --repo owner/repo --state open
# Create issue
gh issue create --title "Bug: something broken" --body "Details..."
# Close issue
gh issue close 42 --repo owner/repo
CI/Workflow Runs:
# List recent runs
gh run list --repo owner/repo --limit 10
# View specific run
gh run view <run-id> --repo owner/repo
# View failed step logs only
gh run view <run-id> --repo owner/repo --log-failed
# Re-run failed jobs
gh run rerun <run-id> --failed --repo owner/repo
API Queries:
# Get PR with specific fields
gh api repos/owner/repo/pulls/55 --jq '.title, .state, .user.login'
# List all labels
gh api repos/owner/repo/labels --jq '.[].name'
# Get repo stats
gh api repos/owner/repo --jq '{stars: .stargazers_count, forks: .forks_count}'
JSON Output:
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 Review Summary:
# Get PR overview for review
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
Issue Triage:
# Quick issue triage view
gh issue list --repo owner/repo --state open --json number,title,labels,createdAt \
--jq '.[] | "[\(.number)] \(.title) - \([.labels[].name] | join(", ")) (\(.createdAt[:10]))"'
适用场景
✅ 使用本技能的时机:
- 检查 PR 状态、审查情况或是否可合并
- 查看 CI/workflow 运行状态和日志
- 创建、关闭或评论 issue
- 创建或合并拉取请求
- 查询 GitHub API 获取仓库数据
- 列出仓库、发布或协作者
限制
❌ 不适用本技能的时机:
- 本地 git 操作(commit、push、pull、branch)→ 直接使用 git
- 非 GitHub 仓库(GitLab、Bitbucket、自托管)→ 使用不同的 CLI
- 克隆仓库 → 使用 git clone
- 审查实际代码变更 → 使用 coding-agent 技能
- 复杂的多文件差异 → 使用 coding-agent 或直接读取文件
注意事项
- 不在 git 目录中时,始终指定
--repo owner/repo - 可直接使用 URL:
gh pr view https://github.com/owner/repo/pull/55 - 存在速率限制;重复查询可使用
gh api --cache 1h