git GitHub Api 下载 zip 或 tarball 链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8377081/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:25:58  来源:igfitidea点击:

GitHub Api download zip or tarball link

gitgithubgithub-api

提问by mkly

There was a good link here about how the zip/tarball string is created

这里有一个关于如何创建 zip/tarball 字符串的很好的链接

When I download a zip from github, what is the hex string at the end of the file name represent?

当我从github下载一个zip文件时,文件名末尾的十六进制字符串代表什么?

But I'm looking at the GitHub APIv3 and I was curious if I'm missing something.

但我正在查看 GitHub APIv3,我很好奇我是否遗漏了什么。

  1. Is there a way to get the zip/tarball link via an API call?

  2. If not, is there a way I can build that string without using the git binary or library? Meaning, can I use various API calls to pull out th data a need and assemble to URL I need?

  1. 有没有办法通过 API 调用获取 zip/tarball 链接?

  2. 如果没有,有没有一种方法可以在不使用 git 二进制文件或库的情况下构建该字符串?意思是,我可以使用各种 API 调用来提取需要的数据并组合到我需要的 URL 中吗?

I know the second question is a little unreasonable for stackoverflow and this is a bit of a fun project for me, so I would prefer on the second question if you just kind of nudged me in the right direction as opposed to throwing down a code snippet. Or just told me if it was possible.

我知道第二个问题对于 stackoverflow 来说有点不合理,这对我来说是一个有趣的项目,所以我更喜欢第二个问题,如果你只是在正确的方向上推动我而不是扔下代码片段. 或者只是告诉我是否可能。

回答by VonC

You can wgetyour way out of the GitHub repo to get a tar file (archive):

您可以wget从 GitHub 存储库中获取一个 tar 文件(存档):

wget --no-check-certificate https://github.com/User/repo/archive/master.tar.gz

# better, if the certificate authorities are present:
wget https://github.com/User/repo/archive/master.tar.gz

will get you a file named 'master' from the user 'User''s repo 'repo'.

将从用户“用户”的存储库“repo”中获取一个名为“master”的文件。

The updated V3 API urlis:

更新的V3 API网址是:

https://api.github.com/repos/User/repo/:archive_format/:ref
#
# two possibilities for fomat:
https://api.github.com/repos/User/repo/tarball/master
https://api.github.com/repos/User/repo/zipball/master

# from github example:
$curl -L https://api.github.com/repos/octokit/octokit.rb/tarball > octokit.tar.gz

You can then tar xpvf master, getting the full archive.
It will create a directory following the naming convention described in the question you mentioned.

然后tar xpvf master,您可以获取完整的存档。
它将按照您提到问题中描述的命名约定创建一个目录。

No git binary is needed to get an archive from GitHub, thanks to their download service "Nodeload".

由于他们的下载服务“Nodeload”,从 GitHub 获取存档不需要 git 二进制文件。



ligemerproposed in an editthe following example:

ligemer在编辑中提出以下示例:

Edit 2016-08-25 - Shell Example With Wget, Variables, and Untar:

编辑 2016-08-25 - 带有 Wget、变量和 Untar 的 Shell 示例:

#!/bin/bash -ex

# arguments:
# token = 
# organization = 
# repo name = 
# branch = 

wget --header="Authorization: token " --header="Accept:application/vnd.github.v3.raw" -O - https://api.github.com/repos///tarball/ | tar xz

Call via:

通过以下方式致电:

$ scriptName.sh token my-organization site.com master

$ scriptName.sh token my-organization site.com master

Above command will download and extract the Github folder to the same directory as the script.

上面的命令将下载 Github 文件夹并将其解压缩到与脚本相同的目录。



Diogo Quintelasuggests in the comments:

Diogo Quintela在评论中建议:

The following example allow the download, extract and cut the top level directory

下面的例子允许下载、解压和剪切顶级目录

curl -L https://api.github.com/repos/octokit/octokit.rb/tarball | tar xz --strip=1 

回答by krlmlr

The syntax is described in the docs:

文档中描述语法:

GET /repos/:owner/:repo/:archive_format/:ref

The following example URL will point (via a 302 redirect) to a zip archive of masterin the hadley/devtoolsrepo:

下面的示例URL将指向(通过302重定向)至zip存档master哈德利/ devtools回购:

https://api.github.com/repos/hadley/devtools/zipball/master

https://api.github.com/repos/hadley/devtools/zipball/master

(The other option for archive_formatis tarball.)

(另一个选项archive_formattarball。)

I have no idea since when this API is available.

我不知道这个 API 什么时候可用。