简体   繁体   中英

How do i get all directory and files in my github repository by using github api?

As the title said. i want get all files and directory from github api.

I found this https://developer.github.com/v3/repos/contents/#get-contents .

GET /repos/:owner/:repo/contents/:path

this api said Gets the contents of a file or directory in a repository. Specify the file path or directory in:path. If you omit:path, you will receive the contents of all files in the repository. Gets the contents of a file or directory in a repository. Specify the file path or directory in:path. If you omit:path, you will receive the contents of all files in the repository.

I call this api without :path it just return file or directory in root path.

response data have git_url field. it have /repos/:owner/:repo/git/trees/:sha api url. this api return file and directory of that have.

My question

  1. Is there a way to get all file and directory information in my repository by calling GitHub api only once?
  2. If 1. is impossible, do I have to recursively call the api (aforementioned git_url field) to get all the files and directory?

Thanks in advance.

If you read the documentation to which you have provided a link, it says:

To get a repository's contents recursively, you can recursively get the tree .

If you read that documentation, there is aa " Get a tree recursively " heading which has exactly what you want:

GET /repos/:owner/:repo/git/trees/:tree_sha?recursive=1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM