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

Response types don't account for parseSuccessResponseBody #606

Open
wolfy1339 opened this issue Feb 6, 2024 · 1 comment · May be fixed by #608
Open

Response types don't account for parseSuccessResponseBody #606

wolfy1339 opened this issue Feb 6, 2024 · 1 comment · May be fixed by #608
Labels
Type: Bug Something isn't working as documented, or is being fixed

Comments

@wolfy1339
Copy link
Member

wolfy1339 commented Feb 6, 2024

Yeah, the return type is a problem even without the streaming option too. TypeScript thinks it’s a normal shaped response object, but instead it returns an ArrayBuffer iirc.

Originally posted by @amacneil in octokit/rest.js#12 (comment)


Here is the magic required to stream release assets to a file using rest.js, typescript, and async/await:

import { Octokit } from "@octokit/rest";
import { createWriteStream } from "node:fs";
import { join } from "node:path";
import { pipeline } from "node:stream/promises";

async function fetchAsset() {
  const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
  const asset = await octokit.rest.repos.getReleaseAsset({
    owner: "foxglove",
    repo: "app",
    asset_id: 12345,
    headers: {
      accept: "application/octet-stream",
    },
    request: {
      parseSuccessResponseBody: false, // required to access response as stream
    },
  });

  const assetStream = asset.data as unknown as NodeJS.ReadableStream;
  const outputFile = createWriteStream(join("outputdir", "file.zip"));
  await pipeline(assetStream, outputFile);
}

Originally posted by @amacneil in octokit/rest.js#12 (comment)

Copy link
Contributor

github-actions bot commented Feb 6, 2024

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@github-project-automation github-project-automation bot moved this to 🆕 Triage in 🧰 Octokit Active Feb 6, 2024
@wolfy1339 wolfy1339 changed the title The types for the response don't seem to account for the different options, like parseSuccessResponseBody *** Here is the magic required to stream release assets to a file using rest.js, typescript, and async/await: Response don't account for parseSuccessResponseBody Feb 6, 2024
@wolfy1339 wolfy1339 changed the title Response don't account for parseSuccessResponseBody Response types don't account for parseSuccessResponseBody Feb 6, 2024
@wolfy1339 wolfy1339 added the Type: Bug Something isn't working as documented, or is being fixed label Feb 6, 2024
@wolfy1339 wolfy1339 moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented, or is being fixed
Projects
Status: 🔥 Backlog
Development

Successfully merging a pull request may close this issue.

1 participant