Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign up`octokit.repos.getArchiveLink()` not working in browser #881
Comments
|
Unfortunately this is currently blocked by GitHub’s APIs which doesn’t expose the client.repos.getArchiveLink({
method: 'HEAD',
owner: 'octocat',
repo: 'Hello-World',
archive_format: 'tarball',
ref: 'master'
})
.then(response => {
console.log(response.headers.location)
})Sorry for all the trouble, it’s all a bit more complicated with the JavaScript Octokit. I’ll follow up with the Hubbers on the state of that If you like you can create a separate issue describing what exactly you are trying to achieve and I’ll help you to find the best workaround for now? Also let me know if your code is run in Node.js or Browser |
|
It looks like GitHub just exposed the fetch('https://api.github.com/repos/octocat/Hello-World/tarball/master', {method: 'HEAD', redirect: 'manual'})
.then(response => {
console.log(response.headers.get('location'))
})I’m now pretty sure that it’s not possible to access headers from a redirect response due to security concerns. However the above code works with |
|
what is possible is this: fetch('https://api.github.com/repos/octocat/Hello-World/tarball/master', {method: 'HEAD'})
.then(response => {
console.log(response.url)
})But the CORS setting of the codeland.github.com does not allow for that at this point, I contacted the API team |
|
I got a response from GitHub support that they are looking into updating the CORS setting for codeland.github.com |
|
I just bumped into this today. Here's how I'm working around it for now on a private repo: const got = require('got')
const { headers } = await got('https://api.github.com/repos/github/some-private-repo/tarball', {
json: true,
followRedirect: false,
headers: {
accept: 'application/vnd.github.v3+json',
authorization: `token ${process.env.GITHUB_TOKEN}`
}
})
console.log(headers.location)
// https://codeload.github.com/github/some-private-repo/legacy.tar.gz/master?token=XXX |
|
You shouldn’t need a workaround for Node, it looks like there is actually a bug, we should set I’ll look into it |
|
@zeke it now works in Node https://runkit.com/gr2m/octokit-rest-js-881/1.1.0
|
Any word from them on this? I bumped into this, today, while exploring an idea. |
|
No update I’m afraid. What’s your use case? Make sure to contact support and ask them about it. The more people ask about it, the more likely someone will look into it. Reference this issue :) |
I am hoping to implement a simple SPA that would allow an individual user to fetch small repos that the SPA would then manipulate prior to user downloading them.
Done. Thanks for the suggestion. :-) |





this is a follow up for #736 about
.repos.getArchiveLinkOne way to handle it is to add a new flag like "hasRedirectResponse" in
lib/routes.json. If it is set then the method should beHEADand the method should return with the value of theLocationresponse header. Note that it’s currently not accessible usingfetch, the GitHub API needs to return an additional header, see https://stackoverflow.com/a/38975988/206879Another alternative would be only replace
repos.getArchiveLinkwithrepos.getArchiveand then add to the documentation that if the user does not want to follow the redirect, they have to setmethod: 'HEAD'in the request options and then read out the URL from the response’s headers location