github-api - 用于下载包含 LFS 文件的 zipball/tarball 的 Github API

标签 github-api git-lfs

我正在使用 v3 API 从 Github 检索 tarball,即 https://api.github.com/repos/my-account/my-project/tarball/my-ref

但是,该项目对某些文件使用 Git-LFS,生成的存档不包含这些文件,但包含 LFS 链接:

version https://git-lfs.github.com/spec/v1
oid sha256:fc03a2eadf6ac4872de8ad96a865ed05c45c416c5ad40c9efa3c4bcbe5d0dc9e
size 1284

如何才能获得将 LFS 链接替换为真实文件内容的存档?

最佳答案

Git-lfs API显示如何以及在何处提出请求。 在您的情况下,假设您知道要查找的 OID (它存储在 pointer 中),您应该:

POST https://github.com/your-account/your-repo/objects 内容如下:

{
    "operation": "download",
    "objects": [
      {
       "oid": "fc03a2eadf6ac4872de8ad96a865ed05c45c416c5ad40c9efa3c4bcbe5d0dc9e",
       "size": 1284
      }
    ]
}

也许您可以省略 size 部分 - 它并未真正指定。您还可以在batch request中一起请求多个OID

响应将类似于 this并且将包含 blob 本身的下载链接(如果它们存在)或每个 blob 的一些错误(如果您通过身份验证,则整个响应始终返回 200)。

关于github-api - 用于下载包含 LFS 文件的 zipball/tarball 的 Github API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36552879/

相关文章:

android - GitHub API : finding number of stars, 提交和发布

authorization - GitHub API Ping

ubuntu-14.04 - git 仅在 Gitlab CI 上为 LFS 文件克隆 sha

使用 Google Cloud Storage 的 Git 大文件存储

git - 如何忽略 Git LFS 无法找到源

git 从 LFS 迁移到普通仓库

macos - Jenkins 多分支管道 : git-lfs command not found on Mac node

github - GitHub GraphQL API 可以在存储库中创建文件吗?

search - Github GraphQL 搜索与过滤

javascript - 用于链接 header 的 Node.js 解析器?