英文:
curl zipball or tarball from private GitHub release
问题
以下是翻译好的部分内容:
要成功下载GitHub私有存储库的二进制tarball或zipball,必须使用特定的语法。我们已经尝试了以下方法:
从此链接的文档开始,我已经尝试了以下操作,但结果不如预期,具体描述如下:
文档中的以下命令返回JSON响应,但没有文件:
curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/AccountName/RepoName/releases/tags/vers.a.b.c --ssl-no-revoke
由前述命令返回的zipball和tarball地址如下:
"tarball_url": "https://api.github.com/repos/AccountName/RepoName/tarball/vers.a.b.c",
"zipball_url": "https://api.github.com/repos/AccountName/RepoName/zipball/vers.a.b.c",
使用前述命令返回的URL进行Curl操作
接下来,我尝试了以下命令,将前述命令的tarball_url
放入Curl命令中。但是下面的命令返回一个名为vers.a.b.c
的0KB空文件:
curl -O -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/AccountName/RepoName/tarball/vers.a.b.c --ssl-no-revoke
Curl GitHub网站GUI中给定的URL
最后,我在GitHub.com GUI的私有存储库的发布页面中使用Web浏览器导航到页面,并右键单击“Source code (zip)”链接,选择“复制链接地址”以获取适用于GitHub GUI网站的zipball的URL。我使用该URL组装了以下命令。但是下面的命令返回一个空的zipball:
curl -O -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://github.com/AccountName/RepoName/archive/refs/tags/vers.a.b.c.zip --ssl-no-revoke
要求跨平台并使用cURL。我们目前正在测试这个问题的初始环境必须是Windows命令提示符。
BK2204的建议
根据BK2204的建议,我尝试了以下命令:
curl -L -O -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/AccountName/RepoName/tarball/vers.a.b.c --ssl-no-revoke
结果是一个包含311行难以阅读的文本文件,不确定这些难以阅读的行是否代表了压缩数据。但无论如何,该文件在当前形式下无法使用。
要成功下载tarball或zipball,必须使用何种精确语法?
英文:
What specific syntax must be used in order to download a binary tarball or zipball from a GitHub Release of a private GitHub repository?
Here is what we have tried:
Starting with documentation at this link, I have pursued the following with undesired failed results described as follows:
The following command from docs gives JSON response, but no artifact:
curl -L -H "Accept: application/vnd.github+json" -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/AccountName/RepoName/releases/tags/vers.a.b.c --ssl-no-revoke
The zipball and tarball addresses returned by the preceding command look like:
"tarball_url": "https://api.github.com/repos/AccountName/RepoName/tarball/vers.a.b.c",
"zipball_url": "https://api.github.com/repos/AccountName/RepoName/zipball/vers.a.b.c",
Curl the URLs given by the preceding command
Next, I tried the following line, which puts the tarball_url
from the preceding command's output into a curl command. But the following line returns a 0KB empty file named vers.a.b.c
curl -O -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/AccountName/RepoName/tarball/vers.a.b.c --ssl-no-revoke
Curl the URL given in the GitHub website GUI
Finally, I navigated a web browser in the GitHub.com GUI to the Release page of the private repository and I right-clicked on the Source code (zip)
link and chose "Copy link address" to get the URL that serves the zipball for users of the GitHub UI website. And I assembled the following command using the URL that works for point-and-click human users of the GUI. But the following command returns an empty zipball.
curl -O -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://github.com/AccountName/RepoName/archive/refs/tags/vers.a.b.c.zip --ssl-no-revoke
The requirement is to be cross-platform and to use cURL. The initial environment in which we are testing this must be windows cmd.
BK2204's suggestion
Per bk2204's suggestion below, I tried the command:
curl -L -O -H "Authorization: Bearer ghp_long8alpha8numeric8token" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/AccountName/RepoName/tarball/vers.a.b.c --ssl-no-revoke
The result is a 20 KB text file that contains 311 unreadable lines. Not sure if the unreadable lines represent compressed data. But the file is unusable in its present form regardless.
What precise syntax must be used to successfully download the tarball or zipball?
答案1
得分: 1
以下是要翻译的内容:
第二组curl命令您正在使用(用于获取tarball_url
和zipball_url
的值)需要使用-L
选项来执行curl,因为它们总是会重定向到另一个位置,而-L
选项表示应该跟随重定向。
您可以通过使用-v
选项来执行curl,查看在这种情况下您是否收到了3xx请求,该选项会打印已发送和已接收的标头。
在GitHub上提供归档和原始文件的服务位于一个单独的域上,重定向将指向该域上的URL,即codeload.github.com
。但是,通过使用API是正确的做法,因为codeload.github.com
不使用相同类型的令牌,因此通过使用API进行请求,您将收到一个包含codeload.github.com
将验证以提供所需的tarball或zipball的临时令牌的重定向。
您不应该将域github.com
用于自动化请求,包括归档,因为该域不设计用于处理自动化请求,并且比API具有更严格的速率限制。大量自动化请求主域(除HTTPS Git请求之外)可能会导致您在一段时间内收到429状态码。
要使用的特定语法如下:
curl -H "Authorization: Bearer $TOKEN" -L \
-o foo.tar.gz \
https://api.github.com/repos/$OWNER/$NAME/tarball/$REV
您需要替换$TOKEN
,$OWNER
,$NAME
和$REV
。或者,您可以将URL替换为从tarball_url
或zipball_url
接收的URL,具体视情况而定。
请注意,如果您没有收到预期的结果,您可能没有正确进行身份验证,您应该使用-v
选项来查看您收到了什么状态码。我已经验证过这个语法可以从我的私有仓库下载。
英文:
The second set of curl commands you're using (the ones that fetch the tarball_url
and zipball_url
values) need to use the -L
option to curl, because they will always redirect to another location, and the -L
option indicates that redirects should be followed.
You can see that you're receiving a 3xx request in this case by using the -v
option to curl, which prints the headers sent and received.
The service that serves archives and raw files at GitHub is on a separate domain, and the redirect will be to a URL on that domain, codeload.github.com
. However, you're doing the right thing by using the API, because codeload.github.com doesn't use the same kind of tokens, so by accessing the API with your request, the redirection you receive will contain a temporary token that codeload.github.com will verify to give you the desired tarball or zipball.
You should not use the domain github.com
for automated requests, including archives, because that domain is not designed to handle automated requests and has much stricter rate limits than the API. Making a substantial number of automated requests to the main domain (outside of HTTPS Git requests) will likely result in you receiving a 429 for some time.
The specific syntax to use is this:
curl -H "Authorization: Bearer $TOKEN" -L \
-o foo.tar.gz \
https://api.github.com/repos/$OWNER/$NAME/tarball/$REV
You will need to substitute $TOKEN
, $OWNER
, $NAME
, and $REV
. Instead, you may replace the URL with the one received from tarball_url
or zipball_url
, as appropriate.
Note that if you are not receiving the expected results, you are probably not authenticating correctly, and you should use the -v
option to see what status code you're receiving. I have verified that this syntax works to download from my private repository.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论