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

How do i upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? #2600

Open
1 task done
xts-bit opened this issue Dec 30, 2023 · 1 comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@xts-bit
Copy link

xts-bit commented Dec 30, 2023

What happened?

How do I upload a folder that contains all my code files to my Github repo using Github's REST API programmatically? Can anyone help me do that in JavaScript with Node.js?

Currently, when I try to run my code, it only uploads files, but how do I upload a folder instead? I don't want to upload files one by one. Any idea what to do?

Versions

Latest version

Relevant log output

async function upload() {
  const message = 'amogus';
  const content = 'aaaaa';
  const owner = 'MY-USERNAME';
  const repo = 'MY-REPO-NAME';
  const path = 'my-project';
  const auth = '{MY ACCESS TOKEN HERE}';

  const existingFile = await (await fetch(
    `https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
    {
      method: 'GET',
      headers: {
        Accept: 'application/vnd.github+json',
        Authorization: `Bearer ${auth}`
      }
    }
  )).json();

  await (await fetch(
    `https://api.github.com/repos/${owner}/${repo}/contents/${path}`,
    {
      method: 'PUT',
      headers: {
        Accept: 'application/vnd.github+json',
        Authorization: `Bearer ${auth}`
      },
      body: JSON.stringify({
        message: message,
        content: btoa(content),
        sha: existingFile.sha,
      }),
    }
  )).json();
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@xts-bit xts-bit added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Dec 30, 2023
Copy link

👋 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! 🚀

@wolfy1339 wolfy1339 added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs and removed Type: Bug Something isn't working as documented Status: Triage This is being looked at and prioritized labels Dec 30, 2023
@nickfloyd nickfloyd moved this from 🆕 Triage to 🏗 In progress in 🧰 Octokit Active Jan 4, 2024
@kfcampbell kfcampbell moved this from 🏗 In progress to 🔥 Backlog in 🧰 Octokit Active Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
Status: 🔥 Backlog
Development

No branches or pull requests

2 participants