简体   繁体   English

如何使用 github api 获取 github 存储库中的所有目录和文件?

[英]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.我想从 github api 获取所有文件和目录。

I found this https://developer.github.com/v3/repos/contents/#get-contents .我发现了这个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.这个 api 表示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.我称之为 api 没有:path它只是返回root路径中的文件或目录。

response data have git_url field.响应数据有git_url字段。 it have /repos/:owner/:repo/git/trees/:sha api url.它有/repos/:owner/:repo/git/trees/:sha api url。 this api return file and directory of that have.这个 api 返回文件和目录。

My question我的问题

  1. Is there a way to get all file and directory information in my repository by calling GitHub api only once?有没有办法通过只调用一次 GitHub api 来获取我的存储库中的所有文件和目录信息?
  2. If 1. is impossible, do I have to recursively call the api (aforementioned git_url field) to get all the files and directory?如果1.不可能,我是否必须递归调用 api (上述git_url字段)来获取所有文件和目录?

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 .要递归地获取存储库的内容,您可以递归地获取 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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