簡體   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