繁体   English   中英

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

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

正如标题所说。 我想从 github api 获取所有文件和目录。

我发现了这个https://developer.github.com/v3/repos/contents/#get-contents

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

这个 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.

我称之为 api 没有:path它只是返回root路径中的文件或目录。

响应数据有git_url字段。 它有/repos/:owner/:repo/git/trees/:sha api url。 这个 api 返回文件和目录。

我的问题

  1. 有没有办法通过只调用一次 GitHub api 来获取我的存储库中的所有文件和目录信息?
  2. 如果1.不可能,我是否必须递归调用 api (上述git_url字段)来获取所有文件和目录?

提前致谢。

如果您阅读了提供链接的文档,它会说:

要递归地获取存储库的内容,您可以递归地获取 tree

如果您阅读了该文档,则会有一个“递归获取树”标题,其中包含您想要的内容:

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

暂无
暂无

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

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