Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Api: How to get Root :tree_sha of a repository?

How do I get the Root :tree_sha of a GitHub repository via the GitHub API?

The GitHib API help pages don't seem to explain this critical piece of information:

http://develop.github.com/p/object.html

Can get the contents of a tree by tree SHA

tree/show/:user/:repo/:tree_sha

To get a listing of the root tree for the facebox project from our commit listing, we can call this:

$ curl http://github.com/api/v2/yaml/tree/show/defunkt/facebox/a47803c9ba26213ff194f042ab686a7749b17476

like image 731
Chris Jacob Avatar asked May 14 '10 00:05

Chris Jacob


1 Answers

Each commit contains the sha of the entire tree as of that commit. Use the API to get a JSON object representing the master branch.

https://api.github.com/repos/:owner/:repo/branches/master

That branch's last commit includes the tree's sha that I think you're asking for.

This bit of code demonstrates how to get the head_tree_sha in Python.

import requests
token = '0...f'
key = {'Authorization':'token '+token}
master = requests.get('https://api.github.com/repos/'+owner+'/' + repo '/branches/master', headers=key)
master = master.json()
head_tree_sha = master['commit']['commit']['tree']['sha']

https://developer.github.com/v3/git/commits/

like image 87
Bennett Brown Avatar answered Oct 14 '22 03:10

Bennett Brown