GitHub Api 下载 zip 或 tarball 链接 [英] GitHub Api download zip or tarball link
问题描述
这里有一个关于如何创建 zip/tarball 字符串的很好的链接
There was a good link here about how the zip/tarball string is created
我从github下载zip文件时,文件名末尾的十六进制字符串代表什么?
但我正在查看 GitHub APIv3,我很好奇我是否遗漏了什么.
But I'm looking at the GitHub APIv3 and I was curious if I'm missing something.
有没有办法通过 API 调用获取 zip/tarball 链接?
Is there a way to get the zip/tarball link via an API call?
如果没有,有没有一种方法可以在不使用 git 二进制文件或库的情况下构建该字符串?意思是,我可以使用各种 API 调用来提取需要的数据并组合到我需要的 URL 中吗?
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?
我知道第二个问题对于stackoverflow来说有点不合理,这对我来说是一个有趣的项目,所以如果你只是在正确的方向上推动我而不是放弃,我更喜欢第二个问题一个代码片段.或者只是告诉我是否可能.
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.
推荐答案
您可以 wget
从 GitHub 存储库中获取一个 tar 文件(存档):
You can wget
your way out of the GitHub repo to get a tar file (archive):
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
将从用户用户"的存储库repo"中获取一个名为master"的文件.
will get you a file named 'master' from the user 'User''s repo 'repo'.
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
然后您可以tar xpvf master
,获取完整档案.它将按照 你提到的问题.
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.
由于他们的 下载服务Nodeload".
编辑 2016-08-25 - 带有 Wget、变量和 Untar 的 Shell 示例:
#!/bin/bash -ex
# arguments:
# token = $1
# organization = $2
# repo name = $3
# branch = $4
wget --header="Authorization: token ${1}" --header="Accept:application/vnd.github.v3.raw" -O - https://api.github.com/repos/${2}/${3}/tarball/${4} | tar xz
通过以下方式调用:
$ scriptName.sh token my-organization site.com master
上面的命令将下载 Github 文件夹并将其解压到与脚本相同的目录中.
The command above will download and extract the Github folder to the same directory as the script.
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
这篇关于GitHub Api 下载 zip 或 tarball 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!