Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub API: Fetch all folders and Files in Single GET Request

In the GitHub API, I can issue a GET request of

https://api.github.com/repos/owner/repo/git/trees/master?recursive=1

to recursively fetch all of the trees of a repository. In addition to giving me all of the directories, it gives me URLs that I can use to download individual files:

[...]
{
    "mode": "100644",
    "type": "blob",
    "sha": "abc1234",
    "path": "path/to/file.txt",
    "size": 104361,
    "url": "https://api.github.com/repos/owner/repo/git/blobs/abc1234"
},
[...]

While the recursive=1 piece prevents me from having to make a new GET request for every directory in the repository, I still have to make an individual call for every file. I've looked through the GitHub API Docs, but they don't present a way to do this. It's very likely that there simply isn't a way to fetch all files and folders in a single request, but I wanted to ask here to verify that I have no other option.

like image 243
Doctor Blue Avatar asked Feb 06 '13 14:02

Doctor Blue


1 Answers

The only way to do it with a single request is to get the current contents as an archive: https://docs.github.com/en/rest/reference/repos#download-a-repository-archive

Actually, it's 2 requests since the initial response is a 302 redirect.

like image 53
Ivan Zuzak Avatar answered Oct 21 '22 07:10

Ivan Zuzak