Github api queries
Query GitHub API for pull requests and issues within a date range, retrieving all metadata needed for metrics collection. Use this skill whenever you need to fetch GitHub PR or issue data with date filtering, especially when gathering activity reports or computing statistics across a time period.From its SKILL.md
npx -y skills add cxcscmu/SkillLearnBench --skill github-api-queriesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
3.1 KB, 768 tokens by cl100k_base, as published. Nobody here has run it
GitHub API Queries for Metrics Collection
This skill demonstrates how to query the GitHub API for pull requests and issues using the gh CLI tool, extracting all necessary metadata for downstream analysis.
Prerequisites
ghCLI installed and authenticated to GitHub- Target repository in the format
owner/repo(e.g.,cli/cli) - Date range for filtering (e.g.,
2024-12-01..2024-12-31)
Querying Pull Requests
Use gh pr list with date filtering to retrieve all PRs created during a period:
gh pr list --repo cli/cli \
--state all \
--search "created:2024-12-01..2024-12-31" \
--json number,title,author,createdAt,mergedAt,closedAt,state \
--limit 1000
Key flags:
--state all: Includes both open and closed PRs--search "created:2024-12-01..2024-12-31": GitHub search syntax for date ranges--json: Specify exact fields needed (number, author, timestamps, state)--limit 1000: Fetch up to 1000 results (pagination handled bygh)
Important fields for metrics:
number: PR identifierauthor: Object withloginfield for contributor trackingcreatedAt: ISO timestamp for PR creationmergedAt: ISO timestamp for merge (null if not merged)closedAt: ISO timestamp for closure (null if still open)state: OPEN, CLOSED, or MERGED
Querying Issues
Use gh issue list for issues:
gh issue list --repo cli/cli \
--state all \
--search "created:2024-12-01..2024-12-31" \
--json number,title,labels,createdAt,closedAt,state \
--limit 1000
Key fields for metrics:
labels: Array of label objects withnamefield (use for bug detection)closedAt: Timestamp for closure (null if still open)
Error Handling
If gh returns a rate limit error, wait and retry:
# Check remaining API quota
gh api rate_limit
If authentication fails, ensure:
gh auth status
Output Format
Both queries return JSON arrays. Each item includes the fields specified in --json. Example PR object:
{
"number": 12345,
"title": "Add feature X",
"author": {
"login": "octocat"
},
"createdAt": "2024-12-05T14:30:00Z",
"mergedAt": "2024-12-10T16:45:00Z",
"closedAt": null,
"state": "MERGED"
}
Date Format
All timestamps use ISO 8601 format (UTC). For calculations, parse with standard datetime libraries:
- Python:
datetime.fromisoformat() - JavaScript:
new Date()orDate.parse() - Bash: Convert via epoch for arithmetic
Tips for Reliability
- Always use
--limit 1000or higher to ensure all results are captured (verify count matches expectation) - Dates must use
YYYY-MM-DDformat in search queries - Include both endpoints of the range (results are inclusive of both dates)
- When comparing timestamps, ensure consistent timezone handling (all GitHub timestamps are UTC)
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.