agentsclimarketplace

Github api pagination

Skill cxcscmu/SkillLearnBench/skills/b1-one-shot-claude-sonnet-4-6/github-repo-analytics/github-api-pagination

How to use `gh api` with pagination to retrieve all results from GitHub REST API endpoints, including PRs and issues.From its SKILL.md

Install
npx -y skills add cxcscmu/SkillLearnBench --skill github-api-pagination

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

2.4 KB, 690 tokens by cl100k_base, as published. Nobody here has run it

GitHub API Pagination with gh api

Overview

GitHub REST API returns paginated results (default 30, max 100 per page). Use gh api with --paginate to automatically fetch all pages.

Basic Usage

# Fetch all pages automatically
gh api --paginate /repos/OWNER/REPO/pulls \
  -X GET \
  -f state=all \
  -f per_page=100

# Use GraphQL for complex queries (no pagination needed for small sets)
gh api graphql -f query='...'

REST API: List PRs with Date Filtering

# Get all PRs created in December 2024 (state=all includes open/closed/merged)
gh api --paginate \
  "repos/cli/cli/pulls?state=all&per_page=100&sort=created&direction=desc" \
  --jq '.[] | select(.created_at >= "2024-12-01T00:00:00Z" and .created_at < "2025-01-01T00:00:00Z")'

Note: --jq applies a jq filter to each page's output.

REST API: List Issues with Date Filtering

gh api --paginate \
  "repos/cli/cli/issues?state=all&per_page=100&sort=created&direction=desc" \
  --jq '.[] | select(.pull_request == null)'  # exclude PRs from issues endpoint

Search API (Efficient for Date Ranges)

The Search API is better for date-bounded queries:

# PRs created in Dec 2024
gh api --paginate \
  "search/issues?q=repo:cli/cli+is:pr+created:2024-12-01..2024-12-31&per_page=100" \
  --jq '.items[]'

# Issues created in Dec 2024
gh api --paginate \
  "search/issues?q=repo:cli/cli+is:issue+created:2024-12-01..2024-12-31&per_page=100" \
  --jq '.items[]'

Combining Pages into a Single JSON Array

# Collect all pages into a single JSON array using --paginate + jq slurp
gh api --paginate \
  "repos/cli/cli/pulls?state=all&per_page=100" \
  --jq '.[]' | jq -s '.'

Key Fields

FieldDescription
created_atISO8601 timestamp when PR/issue was created
merged_atISO8601 timestamp when PR was merged (null if not merged)
closed_atISO8601 timestamp when PR/issue was closed
stateopen, closed
pull_request.merged_atFor search API results
labels[].nameArray of label objects with name field
user.loginAuthor's GitHub username

Rate Limits

  • REST API: 5000 requests/hour (authenticated)
  • Search API: 30 requests/minute (authenticated)
  • Use gh api -i to see rate limit headers

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.