0penBrain found a clever way to obtain this information and detailed it in the following Gist : https://gist.github.com/0penBrain/7be59a48aba778c955d992aa69e524c5
Here's the relevant snippet with curl
:
curl -I -k "https://api.github.com/repos/:owner/:repo/commits?per_page=1" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p'
The trick is to enable a 1 commit per page pagination, as can be seen in the query-string.
Then the focus must shift from the response JSON body to the HTTP headers where the following entry can be found :
link: <https://api.github.com/repositories/27193779/commits?per_page=1&page=2>; rel="next", <https://api.github.com/repositories/27193779/commits?per_page=1&page=37949>; rel="last"
The sed
expression is then in charge of extracting the 37949
number (in this example)