Skip to content
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

Redirect on GetBranch #1895

Closed
asraa opened this issue Jun 15, 2021 · 4 comments
Closed

Redirect on GetBranch #1895

asraa opened this issue Jun 15, 2021 · 4 comments
Assignees
Labels
Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). enhancement good first issue

Comments

@asraa
Copy link

asraa commented Jun 15, 2021

It's common for master branch to be renamed to main branch.

I noticed that when trying to get a renamed master branch, I normally get a 301:

$ curl -i  -H "Accept: application/vnd.github.v3+json"   https://api.github.com/repos/asraa/asraa.github.io/branches/master
HTTP/2 301 
server: GitHub.com
date: Tue, 15 Jun 2021 15:31:51 GMT
content-type: application/json; charset=utf-8
content-length: 190
x-oauth-scopes: public_repo, read:org
x-accepted-oauth-scopes: 
location: https://api.github.com/repositories/asraa/asraa.github.io/branches/main
x-github-media-type: github.v3; format=json
x-ratelimit-limit: 5000
x-ratelimit-remaining: 4628
x-ratelimit-reset: 1623773879
x-ratelimit-used: 372
x-ratelimit-resource: core
access-control-expose-headers: ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset
access-control-allow-origin: *
strict-transport-security: max-age=31536000; includeSubdomains; preload
x-frame-options: deny
x-content-type-options: nosniff
x-xss-protection: 0
referrer-policy: origin-when-cross-origin, strict-origin-when-cross-origin
content-security-policy: default-src 'none'
vary: Accept-Encoding, Accept, X-Requested-With
x-github-request-id: AEFA:589F:209F980:435C7FE:60C8C7E7

{
  "message": "Moved Permanently",
  "url": "https://api.github.com/repositories/asraa/asraa.github.io/branches/main",
  "documentation_url": "https://docs.github.com/v3/#http-redirects"
}

But using go-github, I get a 404 response. Is there any way to handle the 301 response and include the redirect URL in the response body when calling GetBranch?

@asraa
Copy link
Author

asraa commented Jun 15, 2021

I'm confused why it's a 404 and not at least returning the correct status plus the JSON decoding error...

am I missing something?

@gmlewis
Copy link
Collaborator

gmlewis commented Jun 15, 2021

Thank you, @asraa !

We could do something similar to what we did for:

and add a new followRedirects parameters that would take care of the special handling needed to follow a redirect.

This would be a great PR for any new contributor to this repo or a new Go developer.
All contributions are greatly appreciated!

Feel free to volunteer for any issue and the issue can be assigned to you so that others don't attempt to duplicate the work.

Please check out our CONTRIBUTING.md guide to get started.

Thank you!

@gmlewis gmlewis added Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). enhancement good first issue labels Jun 15, 2021
@gmlewis
Copy link
Collaborator

gmlewis commented Jun 15, 2021

I'm confused why it's a 404 and not at least returning the correct status plus the JSON decoding error...

am I missing something?

This will have to be investigated.

@n1lesh
Copy link
Contributor

n1lesh commented Jun 15, 2021

@gmlewis I can work on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking API Change PR will require a bump to the major version num in next release. Look here to see the change(s). enhancement good first issue
Projects
None yet
Development

No branches or pull requests

3 participants