-
-
Notifications
You must be signed in to change notification settings - Fork 28
Fix Github private repo asset downloads by preferring API URL #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Github private repo asset downloads by preferring API URL #139
Conversation
|
jdx/mise#6652 was also caused by this regression. FYI, this GitHub behaviour is reported in https://github.com/orgs/community/discussions/47453. |
|
Hi, thanks for your PR! I'm pretty finicky about my projects (see this blog post for details), so I rarely merge a PR as-is. For larger PRs, I typically use the GitHub PR review process and provide feedback directly on the code, asking you to make some changes. For smaller PRs, where I just want to tweak some small stuff (like doc wording, comments, code formatting, etc.), I don't do a PR review. Whether or not I do a review, there are two options for merging the PR:
Please let me know which approach you'd prefer. If I don't hear from you before I get around to working on this PR I'll go with option 1. Thanks again for your contribution! |
|
Option 2 works for me, I have "Allow edits by maintainers" selected to feel free to force push to the branch as you need, thanks! |
b9c7db3 to
51bcd20
Compare
Private GitHub repositories require downloading assets via the API endpoint (api.github.com/repos/.../releases/assets/ID) with authentication headers, rather than direct download URLs (github.com/.../releases/download/...), which only work for public repos. This commit changes Asset deserialization to prefer the `url` (API endpoint) field over `browser_download_url`. The existing download_asset method already sets the correct headers (`Accept: application/octet-stream` and `Authorization`) required for API endpoint downloads.
51bcd20 to
8579e0c
Compare
|
Merged. Thanks for working on this! |
|
This was released in v0.8.2. Thanks again! |
Private GitHub repositories require downloading assets via the API endpoint (api.github.com/repos/.../releases/assets/ID) with proper authentication headers, rather than direct download URLs (github.com/.../releases/download/...) which only work for public repos.
Changed Asset deserialisation to prefer
url(API endpoint) overbrowser_download_urlbecause the API endpoint works for both public and private repositories when authentication is provided, while the browser download URL returns 404 for private repos.The existing download_asset method already sets the correct headers (Accept: application/octet-stream and Authorisation) required for API endpoint downloads.
How to reproduce the issue with github and curl
Get the last release form the API
example output:
{ "name": "bar_Darwin_arm64.tar.gz", "url": "https://api.github.com/repos/foo/bar/releases/assets/299331819", "browser_download_url": "https://github.com/foo/bar/releases/download/v0.1.0/bar_Darwin_arm64.tar.gz" }Try the browser download URL on a private repo (failed)
Returns not found - You can add the
-o /tmp/bar.tar.gz, you will see only writes a test file that contains (not found)How to reproduce the issue with ubi
I can attached the debug output if necessary. I had changed the name of the repo for privacy, so foo/bar is not real, but you can test that with a private repo.