Common gh CLI Command Counts Pagination Pages, Not Repository Issues
A developer discovered that the widely used GitHub CLI command 'gh api --paginate --slurp --jq length' counts pages of results rather than individual issues, a mistake that had appeared in a published tutorial receiving nearly 1,800 monthly search impressions. The error stems from how the --slurp flag works: it wraps all paginated responses into an outer array of arrays, so 'length' returns the number of pages, not items. The correct approach requires adding 'add' before 'length' in the jq filter, which first concatenates all page arrays into a single list before counting. Additional nuances include the fact that GitHub's issues endpoint also returns pull requests, requiring an extra filter to exclude them, and that some endpoints return objects rather than bare arrays, demanding a different extraction pattern. The author has since corrected the original tutorial and documented multiple reliable pagination recipes to prevent the same misunderstanding.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in