brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: gh api with jq and pagination pulls every page of results in one command

CLI
~/tips/tip-cli-gh-api-jq-paginate

gh api repos/{owner}/{repo}/issues --paginate --jq '.[] | "\(.number)\t\(.title)"'

Calls any API endpoint with your login and pulls out just the fields you need.

Not every question has a gh subcommand. gh api calls any endpoint with the login you already have, and it has jq built in.

Inside a repository, {owner} and {repo} are filled in for you from the current checkout:

gh api repos/{owner}/{repo}/issues --paginate --jq '.[] | "\(.number)\t\(.title)"'

--paginate keeps requesting the next page until there are none left, so you get every issue instead of the first 30. --jq runs the filter on the result, and you don’t need jq installed for that.

A few more I find handy:

gh api repos/{owner}/{repo}/releases/latest --jq .tag_name
gh api user --jq .login

Writing works too: -f key=value adds a string field and switches the request to POST, so be sure you mean it before you run an example that has -f in it.

With --paginate the filter runs on each page separately. That is fine for listing, but a count or sort with jq then works per page. Add --slurp to get one array of all pages, and pipe that into a standalone jq for the totals. Large paginated queries also eat into your API rate limit, which gh api rate_limit shows.

Further reading: gh api (GitHub CLI manual)

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip rg 'apiKey' -g '!*.min.js' -g '!package-lock.json' All CLI tips (46) All topics

Link