-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: DownloadReleaseAsset handles renamed repository #3392
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: DownloadReleaseAsset handles renamed repository #3392
Conversation
This fixes issue google#3081, such that `Repositories.DownloadReleaseAsset` correctly handles scenarios where a non-`nil` `followRedirectsClient` argument has been passed, but the specified repository has been renamed to a new name. Previously, in such scenarios... 1. The initial `GET /repos/<OWNER>/<REPO>/releases/assets/<ASSET ID>` responds 301 w/ a `Location: <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>`. 2. The `followRedirectsClient` issues a `GET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>` with a `Accept: */*` header. 3. `GET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>` responds 200 with a JSON response body (rather than 302 w/ a `Location: <MEDIA SERVER ASSET URL>` header) due to the presence of the `Accept: */*` header (and the absence of a `Accept: application/octet-stream` header)`from step 2. The following `curl` offers an example of correct redirect follows & correct `Accept: application/octet-stream`-preservation in this scenario: ``` curl \ --verbose \ --location \ --header "Accept: application/octet-stream" \ https://api.github.com/repos/mterwill/go-github-issue-demo/releases/assets/151970555 ``` Now, as per this change: 1. The initial `GET /repos/<OWNER>/<REPO>/releases/assets/<ASSET ID>` responds 301 w/ a `Location: <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>`. 2. The `followRedirectsClient` issues a `GET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>` with a `Accept: application/octet-stream` header [as required by the GH API](https://docs.github.com/en/enterprise-cloud@latest/rest/releases/assets?apiVersion=2022-11-28) 3. `GET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>` responds 302 w/ a `Location: <MEDIA SERVER ASSET URL>`. 4. The `followRedirectsClient` follows the redirects to `GET <MEDIA SERVER ASSET URL>` w/ a `Accept: application/octet-stream` header, and `GET <MEDIA SERVER ASSET URL>` responds 200 w/ the asset contents. Signed-off-by: Mike Ball <[email protected]>
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #3392 +/- ##
==========================================
- Coverage 97.72% 92.21% -5.51%
==========================================
Files 153 173 +20
Lines 13390 14770 +1380
==========================================
+ Hits 13085 13620 +535
- Misses 215 1060 +845
Partials 90 90 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @mdb !
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
This improves `RepositoriesService.DownloadReleaseAsset` documentation to be a bit more specific and accurate, as per: google#3081 (comment) Signed-off-by: Mike Ball <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Awaiting second LGTM+Approval from any other contributor to this repo before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you, @tomfeigin ! |
This fixes issue #3081, such that
Repositories.DownloadReleaseAsset
correctly handles scenarios where a non-nil
followRedirectsClient
argument has been passed, and the specified repository has been renamed to a new name.Previously, in such scenarios...
GET /repos/<OWNER>/<REPO>/releases/assets/<ASSET ID>
responds 301 w/ aLocation: <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>
.followRedirectsClient
issues aGET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>
with aAccept: */*
header.GET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>
responds 200 with a JSON response body (rather than 302 w/ aLocation: <MEDIA SERVER ASSET URL>
header) due to the presence of theAccept: */*
header (and the absence of aAccept: application/octet-stream
header) from step 2.The following
curl
offers an example of correct redirect follows & correctAccept: application/octet-stream
-preservation in this scenario:Now, as per this change:
GET /repos/<OWNER>/<REPO>/releases/assets/<ASSET ID>
responds 301 w/ aLocation: <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>
.followRedirectsClient
issues aGET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>
with aAccept: application/octet-stream
header as required by the GH API.GET <GH API HOST>/repositories/<REPO ID>/releases/assets/<ASSET ID>
responds 302 w/ aLocation: <MEDIA SERVER ASSET URL>
.followRedirectsClient
follows the redirects toGET <MEDIA SERVER ASSET URL>
w/ aAccept: application/octet-stream
header, andGET <MEDIA SERVER ASSET URL>
responds 200 w/ the asset contents.