【问题标题】:Having trouble downloading Git archive tarballs from Private Repo从 Private Repo 下载 Git 归档 tarball 时遇到问题
【发布时间】:2023-03-23 06:45:01
【问题描述】:

我需要能够以特定标签下载我们的应用程序,但我无法找到一个可行的解决方案。下载基于 git tag 的 tarball 似乎很有希望,但我无法使用 Curl 让它工作。我尝试了以下方法,但我得到的只是 github 404 页面的源代码。

curl -sL https://github.com/$ACCOUNT/$PRIVATE_REPO/tarball/0.2.0.257m?login=$MY_USER_NAME&token=$MY_TOKEN > 0.2.0.257m.tar

【问题讨论】:

  • 您是否在公共仓库中尝试过相同的 URL 方案?
  • 你试过wget吗?或者只是使用 git 从特定标签中克隆代码?

标签: git github


【解决方案1】:

对于公共回购,您有this gist 列出了一些示例:

wget --no-check-certificate https://github.com/sebastianbergmann/phpunit/tarball/3.5.5 -O ~/tmp/cake_phpunit/phpunit.tgz

对于私人仓库,请尝试在 post 指令中传递您的凭据信息:

wget --quiet --post-data="login=${login}&token=${token}" --no-check-certificate https://github.com/$ACCOUNT/$PRIVATE_REPO/tarball/0.2.0.257m

或者在 SO 问题“git equivalent to svn export or github workaround”中使用 curl 命令,在以下位置也有详细说明:
A curl tutorial using GitHub's API”。


OP Steven Jp 报告已使curl 命令工作:

最终的 curl 命令最终看起来像这样:

curl -sL --user "${username}:${password}" https://github.com/$account/$repo/tarball/$tag_name > tarball.tar

(为了便于阅读,多行)

curl -sL --user "${username}:${password}" 
  https://github.com/$account/$repo/tarball/$tag_name
  > tarball.tar

【讨论】:

  • 您的第二个链接帮助我完成了工作。最终的 curl 命令最终看起来像这样 curl -sL --user "${username}:${password}" https://github.com/$account/$repo/tarball/$tag_name > tarball.tar
  • @Steven_JP 太好了。我已将您的命令包含在答案中以获得更多可见性。
  • 不确定这些 wget 示例是否仍然有效,但这对我有用:stackoverflow.com/questions/23347134/…
【解决方案2】:

创建access token后,

你可以使用wget:

wget --output-document=<version>.tar.gz \
    https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN>

curl:

curl -L https://api.github.com/repos/<owner>/<repo>/tarball/<version>?access_token=<OAUTH-TOKEN> \
    > <version>.tar.gz

更多信息可以在GitHub's API reference for archive links找到。

【讨论】:

  • 可能是需要加上'--no-check-certificate'参数:wget --no-check-certificate --output-document=&lt;version&gt;.tar.gz https://api.github.com/repos/&lt;owner&gt;/&lt;repo&gt;/tarball/&lt;version&gt;?access_token=&lt;OAUTH-TOKEN&gt;
  • 这是最接近我的一个。唯一的区别是 GitHub api 现在需要请求标头中的令牌。例如。 curl -L -H "Authorization: token &lt;token&gt;" https://api.github.com/repos/&lt;owner&gt;/&lt;repo&gt;/tarball/&lt;tag&gt; &gt; out.tar.gz
【解决方案3】:

在 Github.com 上登录您的私人组织,然后前往此处创建您的令牌: https://github.com/settings/applications#personal-access-tokens

当尝试 Curl 进入您的私人组织时,请使用以下内容:

curl --header 'Authorization: token ADDACCESSTOKENHERE' \
 --header 'Accept: application/vnd.github.v3.raw' \
 --remote-name \
 --location https://api.github.com/repos/ORG/PROJECT/contents/FILE

用您的信息替换 CAPS 中的内容...

【讨论】:

  • 由于某种原因,当一个标头用于身份验证时,我在将带有 curl 的多个标头发送到 Github API 以下载二进制资产时遇到问题。它返回“仅允许一种身份验证机制;仅应指定 X-Amz-Algorithm 查询参数、签名查询字符串参数或授权标头”的 XML 响应。但是,如果我将身份验证从标头更改为查询字符串参数,那么它就可以工作。所以只是提到这个怪癖。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 2015-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多