Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github api get SHA of master

Tags:

github

api

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.

like image 628
Adam Meyer Avatar asked Dec 18 '12 06:12

Adam Meyer


2 Answers

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.

like image 172
Ivan Zuzak Avatar answered Nov 16 '22 23:11

Ivan Zuzak


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?

like image 3
adabru Avatar answered Nov 17 '22 01:11

adabru