Im looking for the SHA of the current master of a github repo.
If I do something like this: https://api.github.com/repos/ameyer/Arduino-L6470/git/trees/master
The returned SHA is 'master'.
I need a way to check if the version of the master on github is newer than what I have in a cached app, and I figured the SHA would be the best way to check.
Try fetching the references:
https://api.github.com/repos/ameyer/Arduino-L6470/git/refs
And then you can:
https://api.github.com/repos/ameyer/Arduino-L6470/git/trees/d0cad097e733c3d9b7051c6f047411c5e3494491
Notice that this second URL gives basically the same result as the URL you tried, only the master
ref name is replaced with the actual sha of the latest commit.
So, basically, just fetch the refs and get the sha of master.
If you don't mind launching a process you can also use "native" git api:
git ls-remote https://github.com/ameyer/Arduino-L6470 master
That would also work for other hosting providers and across http api changes.
original source: How to get SHA of the latest commit from remote git repository?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With