How to get the download link of all files in a repo?

249 Views Asked by At

With the following command, I'm able to get download_url for the files on my GitHub repo, but it doesn't include files that are inside folders:

curl -H "Authorization: token ghp_..." -H "Accept: application/vnd.github.v3.raw" -L "https://api.github.com/repos/<USER>/<REPO>/contents"

While searching around I found this answer, the following command lists all files recursively, but it doesn't include the download_url:

curl -H "Authorization: token ghp_..." -H "Accept: application/vnd.github.v3.raw" -L "https://api.github.com/repos/<USER>/<REPO>/git/trees/main?recursive=1"

How i could get the download_url of ALL files in the repo?

1

There are 1 best solutions below

0
Jaredo Mills On

Construct the download_url using the "path" member of the objects returned from the /repos/{owner}/{repo}/git/trees/{tree_sha} endpoint.

The template appears to be https://raw.githubusercontent.com/{owner}/{repo}/{branch/commit-sha/tree-sha}/{path}