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

[DOCS]: Download a repository archive (zip) #2369

Open
1 task done
sebastianjnuwu opened this issue Jan 1, 2023 · 3 comments
Open
1 task done

[DOCS]: Download a repository archive (zip) #2369

sebastianjnuwu opened this issue Jan 1, 2023 · 3 comments
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Documentation Improvements or additions to documentation
Projects

Comments

@sebastianjnuwu
Copy link

sebastianjnuwu commented Jan 1, 2023

Describe the need

Hello, I was looking at the documentation especially to learn more about the github API and javascript and make my development environment cooler, finally I was looking at this category for make my development environment more pleasant. I came across the following code to download the repository:

const octokit = new Octokit({
  auth: 'YOUR-TOKEN'
})

await octokit.request('GET /repos/{owner}/{repo}/zipball/{ref}', {
  owner: 'OWNER',
  repo: 'REPO',
  ref: 'REF'
})

Wouldn't it be nice in the documentation to have a way to transform it into a file to make it easier?

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@sebastianjnuwu sebastianjnuwu added Status: Triage This is being looked at and prioritized Type: Documentation Improvements or additions to documentation labels Jan 1, 2023
@ghost ghost added this to Documentation in JS Jan 1, 2023
@sebastianjnuwu sebastianjnuwu changed the title [DOCS]: [DOCS]: Download a repository archive (zip) Jan 1, 2023
@kfcampbell kfcampbell added Status: Up for grabs Issues that are ready to be worked on by anyone Priority: Normal and removed Status: Triage This is being looked at and prioritized labels Jan 3, 2023
@sebastianjnuwu
Copy link
Author

Any news about this?

@wolfy1339
Copy link
Member

We introduced a new request option to return data Streams instead of Buffer

octokit/request.js@110f3c4

That should be helpful for your use case.

From there you can simply use the regular fs functions to write that to a file.

const octokit = new Octokit({
  auth: 'YOUR-TOKEN'
})

const { data } = await octokit.request('GET /repos/{owner}/{repo}/zipball/{ref}', {
  request: {
    parseSuccessResponseBody: false
  },
  owner: 'OWNER',
  repo: 'REPO',
  ref: 'REF'
})

fs.writeFileSync("repo.zip", data)

@garrettmaring
Copy link

We introduced a new request option to return data Streams instead of Buffer

octokit/request.js@110f3c4

That should be helpful for your use case.

From there you can simply use the regular fs functions to write that to a file.

const octokit = new Octokit({
  auth: 'YOUR-TOKEN'
})

const { data } = await octokit.request('GET /repos/{owner}/{repo}/zipball/{ref}', {
  request: {
    parseSuccessResponseBody: false
  },
  owner: 'OWNER',
  repo: 'REPO',
  ref: 'REF'
})

fs.writeFileSync("repo.zip", data)

I'm getting the following error for this code:

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of ReadableStream

I'm trying to convert the ReadableStream into a ReadStream (needed for WriteStream) and I'm fumbling :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Issues for participation in Hacktoberfest Status: Up for grabs Issues that are ready to be worked on by anyone Type: Documentation Improvements or additions to documentation
Projects
Status: 🔥 Backlog
JS
  
Documentation
Development

No branches or pull requests

5 participants