-
Notifications
You must be signed in to change notification settings - Fork 60
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
[FEAT]: Allow streaming of the data #601
Comments
For this use case, we recommend you use Like this // https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#download-a-repository-archive-tar
const requestOptions = request.endpoint('GET /repos/{owner}/{repo}/tarball/{ref}', {
owner: 'OWNER',
repo: 'REPO',
ref: 'REF'
})
// {
// method: 'GET',
// url: 'https://api.github.com/repos/OWNER/REPO/tarball/REF',
// headers: {
// accept: 'application/vnd.github.v3+json',
// 'user-agent': 'octokit-core.js/0.0.0-development Node.js/16.20.1 (darwin; arm64)'
// },
// } Note that you will have to set the |
Tbh, this doesnt help me. I just used in our bot built in fetch, because there is no benefit in using a package, if I have to set everything manually. The only benefit of using octokit is the potential typesafety. If i have no typesafety then i dont need the package. |
As i see that you added the "support" tags. If you need support to implement this feature, then could have a look, in providing a PR. |
that's okay, we can't make it work for all possible use cases, everything is a trade off. If this is the only request you need to send, I'd use native fetch, too. |
Sry but this is not what I expected. I did not expected that my issue gets demoted from feature request to a support request. I expected some feedback regarding the possibility to land this feature and maybe the invitation to provide a PR. |
okay if you like to give it a go, you can certainly send a pull request and we can discuss it there. Beware that we are currently discussing an introduction of How do you stream the response with a native fetch currently? Does it work across Node / Browsers / Deno? |
I checked and i realized that i use node-fetch as our bots use still node 16. This is what i do: public processArchive (url: string): Promise<DependabotConfigEntry[]> {
const headers = {
Authorization: 'Bearer ' + this.git.octokit.authToken
}
return new Promise<DependabotConfigEntry[]>((resolve, reject) => {
fetch(url, { method: 'GET', headers })
.then(response => {
if (!response.ok) {
throw new Error(`Failed to fetch ${url}. Status: ${response.status}`)
}
const tarStream = tarList()
const uniqueSet: Set<string> = new Set()
const entries: DependabotConfigEntry[] = []
tarStream.on('entry', function onentry (entry: ReadEntry) {
let directory = dirname(entry.path).slice(entry.path.split(sep)[0].length) || sep
const ecosystem = detectEcosystemByFilepath(basename(entry.path), directory)
if (ecosystem) {
// github-actions need to set the path to root
if (ecosystem === 'github-actions') {
directory = '/'
}
if (uniqueSet.has(ecosystem + '/' + directory) === false) {
entries.push({
'package-ecosystem': ecosystem,
directory,
schedule: {
interval: 'daily'
}
})
uniqueSet.add(ecosystem + '/' + directory)
}
}
})
pipeline(response.body, tarStream, error => {
error
? reject(error)
: resolve(entries)
})
})
.catch(e => {
reject(e)
})
})
} With this implementation memory spikes and alerts are gone from the gcloud logs. |
we cannot rely on |
Sure. Issue was that fetch is afaiknot in @types/node and we already used node-fetch in other parts of the code. I would try to provide a solution with native fetch. |
There is such a thing as read streams with the fetch API https://developer.mozilla.org/en-US/docs/Web/API/Streams_API/Using_readable_streams Writable streams also exist |
This would only require a small modification to the request.js/src/fetch-wrapper.ts Lines 146 to 157 in 60e9b57
Instead of doing anything with |
I created a PR to discuss it further ;) |
🎉 This issue has been resolved in version 8.1.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Glad this was merged! Here's a complete example of streaming release assets from rest.js: |
Is there any documentation on this aside from the linked code above? I'm wondering if it's possible to stream the result of |
You can stream any request you want. although for pure JSON endpoints like the list comments for issue endpoint. you should be using pagination You can pass request options to all API methods |
This is very likely a skill issue on my part as I'm new to HTTP streaming as a concept. I don't want to pollute a closed issue with unnecessary notifications. At the risk of doing that, though, this is what my old code was doing: const response = await octokit.paginate(octokit.issues.listComments, {
owner: site.issues.owner,
repo: site.issues.repo,
issue_number: issueNumber,
per_page: 100,
}); I tried using the above suggestion of |
Feel free to open a discussion instead. We can carry on there |
Describe the need
Currently octokit/request is not configurable to provide the stream of the response.body. This is an issue, if you want to load the tarball of a project and want to stream it to a tar stream and process the file content on the fly.
There should be an option, which results in passing the body as stream, so that we can utilitze it if needed.
SDK Version
No response
API Version
No response
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: