如何从 GitHub 草稿中下载文件

How do I download a file from a GitHub draft

我正在使用 AppVeyor 为 GitHub 存储库设置 CI 并将构建工件上传到名为 CI builds[=27= 的草稿].该文件是例如位于

https://github.com/an_organisation/a_project/releases/tag/untagged-1111aaaacccc0000dddd/filename.tar.gz

并且可以通过浏览器访问和下载。

现在我想从另一个 AppVeyor 项目(即 appveyor.yml 脚本)访问那些上传的工件。我尝试使用以下命令

使用 AppVeyor DownloadFile 命令、curlwget 下载但没有成功
  set DOWNLOAD_FILENAME=filename.tar.gz
  set DOWNLOAD_ADDRESS=https://github.com/an_organisation/a_project/releases/download/untagged-1111aaaacccc0000dddd/$DOWNLOAD_FILENAME

  wget --header "Authorization: token $GH_AUTH_TOKEN" --output-document=$DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS

  wget --auth-no-challenge --header "Accept:application/octet-stream" --output-document=$DOWNLOAD_FILENAME "$DOWNLOAD_ADDRESS?access_token:$GH_AUTH_TOKEN"

  curl -fsSL -G --user "$APPVEYOR_ACCOUNT_NAME:$GH_AUTH_TOKEN" -o $DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS

  curl -fsSL -G -H "Authorization: token $GH_AUTH_TOKEN" -H "Accept: application/octet-stream" -o $DOWNLOAD_FILENAME $DOWNLOAD_ADDRESS

  curl -fsSL -G -H "Authorization: token $GH_AUTH_TOKEN" -H "Accept: application/octet-stream" -o $DOWNLOAD_FILENAME https://api.github.com/repos/an_organisation/a_project/releases/download/untagged-1111aaaacccc0000dddd/

慢慢地我觉得通过GitHubAPI或下载link从草稿中下载文件是不可能的。

下载此类文件的正确命令是什么?

TLDR 使用 Get Release asset API 和 header Accept: application/octet-stream :

curl -OJ -L -H "Accept: application/octet-stream" \
    -H "Authorization: Token $YOUR_TOKEN" \
    "https://api.github.com/repos/$REPO/releases/assets/$ASSET_ID"

您需要有 assetID。为了拥有它,如果您还没有此信息,则需要 releaseID 使用 GET /repos/:user/:repo/releases :

curl -s -H "Authorization: Token $YOUR_TOKEN" \
   "https://api.github.com/repos/$REPO/releases" | jq '.[] | {(.name): .id}'

然后获取资产 ID 使用 GET /repos/:user/:repo/releases/:release_id :

curl -s -H "Authorization: Token $YOUR_TOKEN" \
    "https://api.github.com/repos/$REPO/releases/$RELEASE_ID" | \
    jq -r '.assets[] | {(.id |tostring): .name}'

然后一旦你有了 assetID(顺便说一句,也许你已经有了它)你终于可以使用 GET /repos/:user/:repo/releases/assets/:asset_id with header Accept: application/octet-stream. From the documentation :

To download the asset's binary content, set the Accept header of the request to application/octet-stream. The API will either redirect the client to the location, or stream it directly if possible. API clients should handle both a 200 or 302 response.

以下文件下载到本地:

curl -OJ -L -H "Accept: application/octet-stream" \
    -H "Authorization: Token $YOUR_TOKEN" \
    "https://api.github.com/repos/$REPO/releases/assets/$ASSET_ID"