Daniel
Daniel

Reputation: 23

Why doesn't the GitHub API return all branches for a repository?

As title says. I am facing why this mirror on GitHub don't show output in terminal using this command:

wget --no-check-cert -q -O - "http://api.github.com/repos/bminor/glibc/branches" | grep release

but on GitHub there is for example:

picture

Upvotes: 2

Views: 1764

Answers (1)

Benjamin W.
Benjamin W.

Reputation: 52122

The response is paginated. If you look at response headers:

Link: <https://api.github.com/repositories/13868694/branches?page=2>; rel="next", <https://api.github.com/repositories/13868694/branches?page=10>; rel="last"

you'll see that you're looking at page 1 of 10. You can increase the number of records per page using a query string parameter up to 100:

curl -Lv 'http://api.github.com/repos/bminor/glibc/branches?per_page=100'

but you still have to get the other pages in your case; the desired page is selected using the page query string parameter, e.g.:

$ curl -sL 'http://api.github.com/repos/bminor/glibc/branches?page=2&per_page=100' \
      | jq -r '.[] | select(.name | contains("release")).name'
hjl/release/2.20/master
hjl/x32/release/2.12
hjl/x32/release/2.15

Alternatively, using the GitHub CLI:

gh api --method GET repos/bminor/glibc/branches \
    --raw-fielg page=2 --raw-field per_page=100 \
    --jq '.[] | select(.name | contains("release")).name'

Upvotes: 3

Related Questions