| name | github |
| description | GitHub CLI (gh) tool for retrieving and analyzing GitHub data including pull requests, issues, code search, workflow runs, releases, and repository information. Use when needing to read GitHub PRs, view comments, check CI/CD status, search code across repos, analyze issues, inspect action logs, or query any GitHub data. Focuses on information retrieval and analysis rather than modifications. |
| allowed-tools | Bash(gh repo list:*), Bash(gh repo view:*), Bash(gh pr list:*), Bash(gh pr view:*), Bash(gh pr diff:*), Bash(gh pr checks:*), Bash(gh issue list:*), Bash(gh run list:*), Bash(gh run view:*), Bash(gh search:*), Bash(gh issue view:*) |
GitHub CLI (gh) Skill
This skill provides comprehensive guidance for using the GitHub CLI (gh) tool to retrieve and analyze information from GitHub repositories, pull requests, issues, and workflows.
Prerequisites
Ensure gh is installed and authenticated:
gh --version
gh auth login
gh auth status
Repository Information
Viewing Repository Details
gh repo view owner/repo
gh repo view owner/repo --web
gh api repos/owner/repo
gh api repos/owner/repo --jq '.stargazers_count, .forks_count, .open_issues_count'
gh repo list orgname --limit 100
gh search repos "language:go stars:>1000"
Repository Statistics
gh api repos/owner/repo/contributors
gh api repos/owner/repo/stats/commit_activity
gh api repos/owner/repo/stats/code_frequency
gh api repos/owner/repo/languages
Pull Request Analysis
Viewing PR Information
gh pr list
gh pr list --state all
gh pr list --state merged --limit 100
gh pr list --author username
gh pr list --label "bug"
gh pr list --search "fix memory leak"
gh pr view 123
gh pr view 123 --comments
gh pr view 123 --web
gh pr view 123 --json number,title,author,state,createdAt,closedAt,files
gh pr diff 123
gh pr diff 123 --patch
Analyzing PR Comments and Reviews
gh api repos/owner/repo/issues/123/comments
gh api repos/owner/repo/pulls/123/comments
gh api repos/owner/repo/pulls/123/reviews
gh api repos/owner/repo/pulls/123/comments --jq '.[] | {path: .path, line: .line, body: .body}'
gh pr view 123 --json comments --jq '.comments[].body'
PR File Changes
gh pr view 123 --json files --jq '.files[].path'
gh api repos/owner/repo/pulls/123/files
gh api repos/owner/repo/pulls/123/files --jq '.[] | "\(.filename): +\(.additions) -\(.deletions)"'
gh pr view 123 --json files --jq '.files[].path | select(test(".*\\.go$"))'
Issue Discovery and Analysis
Searching and Listing Issues
gh issue list
gh issue list --state all
gh issue list --label "bug" --label "priority"
gh issue list --assignee @me
gh issue list --search "memory leak"
gh issue list --milestone "v2.0"
gh search issues "org:myorg memory leak"
gh search issues "is:open is:issue label:bug created:>2024-01-01"
gh issue view 456
gh issue view 456 --comments
gh issue view 456 --json title,body,comments,labels,assignees
Issue Analytics
gh issue list --label "bug" --json number --jq 'length'
gh api repos/owner/repo/issues/456/timeline
gh issue list --search "created:2024-01-01..2024-01-31"
gh api repos/owner/repo/issues/456 --jq '.assignees[].login, .user.login'
GitHub Actions and Workflow Analysis
Viewing Workflow Runs
gh run list
gh run list --limit 50
gh run list --workflow "CI"
gh run list --status failure
gh run view 12345
gh run view 12345 --json conclusion,status,displayTitle,startedAt
gh run view 12345 --json name,startedAt,updatedAt --jq '"\(.name) took \(((.updatedAt | fromdateiso8601) - (.startedAt | fromdateiso8601)) / 60 | floor) minutes"'
Analyzing Workflow Logs
gh run view 12345 --log
gh run view 12345 --log-failed
gh run view 12345 --log --job 67890
gh run view 12345 --log | grep -i "error"
gh run view 12345 --log | grep -A 5 -B 5 "test failed"
gh run download 12345 --name logs
Workflow Performance Analysis
gh api repos/owner/repo/actions/workflows/ci.yml/runs
gh run list --workflow "CI" --limit 100 --json conclusion | \
jq 'group_by(.conclusion) | map({conclusion: .[0].conclusion, count: length})'
gh run list --workflow "CI" --status completed --limit 20 --json name,startedAt,updatedAt | \
jq '[.[] | ((.updatedAt | fromdateiso8601) - (.startedAt | fromdateiso8601)) / 60] | add / length'
gh run list --workflow "tests" --limit 50 --json conclusion,headSha | \
jq 'group_by(.headSha) | map(select(length > 1) | {sha: .[0].headSha, results: map(.conclusion)})'
Artifact Analysis
gh run view 12345 --json artifacts --jq '.artifacts[]'
gh run download 12345
gh run download 12345 --name "test-results"
gh api repos/owner/repo/actions/artifacts
gh api repos/owner/repo/actions/artifacts/98765
Code Search and Analysis
Searching Code Across Repositories
gh search code "org:myorg function fetchUser"
gh search code "org:myorg extension:js console.log"
gh search code "org:myorg language:python import pandas"
gh search code "org:myorg TODO"
gh search code "org:myorg FIXME"
gh search code "org:myorg /api/v[0-9]+"
gh search code "org:myorg path:src/ database connection"
Code Navigation
gh api repos/owner/repo/contents/path/to/file.js
gh api repos/owner/repo/contents/path/to/file.js?ref=feature-branch
gh api repos/owner/repo/contents/src
gh api repos/owner/repo/commits?path=src/main.js
Release Information
Viewing Releases
gh release list
gh release list --exclude-drafts
gh release list --limit 10
gh release view v1.0.0
gh release view latest
gh api repos/owner/repo/releases/latest
gh api repos/owner/repo/releases --jq '.[] | {tag: .tag_name, downloads: [.assets[].download_count] | add}'
Advanced Queries
GraphQL Queries for Complex Data
gh api graphql -f query='
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
pullRequests(last: 20, states: MERGED) {
nodes {
number
createdAt
mergedAt
reviews(first: 1) {
nodes {
createdAt
}
}
}
}
}
}
' -f owner=myorg -f repo=myrepo
gh api graphql -f query='
query($owner: String!, $repo: String!) {
repository(owner: $owner, name: $repo) {
issues(last: 50, states: CLOSED) {
nodes {
number
createdAt
comments(first: 1) {
nodes {
createdAt
author {
login
}
}
}
}
}
}
}
' -f owner=myorg -f repo=myrepo
Batch Data Retrieval
gh pr list --state all --limit 1000 --json number,title,createdAt,closedAt,author > prs.json
gh issue list --state all --limit 1000 --json number,title,labels,createdAt > issues.json
gh run list --limit 200 --json displayTitle,conclusion,startedAt,updatedAt > runs.json
Monitoring and Dashboards
PR Review Queue
gh pr list --json number,title,author,createdAt,reviewDecision | \
jq '.[] | select(.reviewDecision == null) | "PR #\(.number): \(.title) by @\(.author.login)"'
gh search prs "is:open is:pr review-requested:@me"
gh pr list --sort updated --json number,title,updatedAt | \
jq '.[] | "PR #\(.number): \(.title) (updated \(.updatedAt))"'
Issue Triage
gh issue list --json number,title,labels | \
jq '.[] | select(.labels | length == 0) | "Issue #\(.number): \(.title)"'
gh issue list --search "updated:<$(date -d '30 days ago' '+%Y-%m-%d')"
gh issue list --label "priority:high" --label "bug"
Best Practices
- Use JSON output for scripting: Add
--json flag for machine-readable output
- Leverage jq for data extraction: Parse JSON responses for specific fields
- Use search syntax: GitHub's search syntax is powerful for filtering
- Handle pagination: Use
--limit or --paginate for large datasets
- Cache API responses: Use
gh api --cache 1h for frequently accessed data
Additional Resources
For more advanced topics: