-
-
Save 0penBrain/7be59a48aba778c955d992aa69e524c5 to your computer and use it in GitHub Desktop.
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' | |
### And that's all ! | |
# I saw many fighting with finding first commit SHA or similar fancy thing. | |
# Here we just rely on the GH API, asking commits at 1 per page and parsing the last page number in the header of the reply (whose body only holds the last commit !) | |
# So this is robust and bandwidth efficient. :) | |
# If one want the commit count of a specific SHA, just use : | |
curl -I -k "https://api.github.com/repos/:owner/:repo/commits?per_page=1&sha=:sha" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p' | |
# And for a specific time (date using ISO 8601 format, 'Z' for UTC) : | |
curl -I -k "https://api.github.com/repos/:owner/:repo/commits?per_page=1&until=yyyy-MM-ddThh:mm:ssZ" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p' |
I have changed little bit in the curl request from
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'
to
curl -I -k "https://api.github.com/api/v3/repos/:owner/:repo/commits?per_page=1" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p'
then it started working
I have changed little bit in the curl request
OK thx. A bit weird because the Gist uses the standard API. Anyway, good you have it to work.
For anyone curious: getting Repository commit counts can be done quite easily with the GraphQL API
https://stackoverflow.com/a/75854793/19264346
I want it in javascript
I want it in javascript
Not a JS expert but something like:
var request = new XMLHttpRequest();
request.open('GET', 'https://api.github.com/repos/:owner/:repo/commits?per_page=1', false);
request.send(null);
request.getResponseHeader('link').match(/"next".*page=([0-9]+).*"last"/)[1];
This is awesome. For anyone wanting to use authenticated calls, replace the
curl -I -k "..."
withgh api -i /repos/:owner/:repo/commits?per_page=1
👍
TYSM for this I spent like half an hour coding a custom Java utility cause I just couldn't get Runtime to work and now I found this. Thank you man. I have to learn more Bash :)
Great. For sake of curiosity, what was the issue ? 😄