Skip to content

githup repo importer #13

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

Open
a6b8 opened this issue Jan 29, 2024 · 0 comments
Open

githup repo importer #13

a6b8 opened this issue Jan 29, 2024 · 0 comments

Comments

@a6b8
Copy link
Contributor

a6b8 commented Jan 29, 2024

const axios = require('axios');
const AdmZip = require('adm-zip');

async function downloadAndExtractGitHubRepo(owner, repo) {
  const zipUrl = `https://github.com/${owner}/${repo}/archive/main.zip`;

  try {
    // Download the ZIP archive
    const response = await axios.get(zipUrl, { responseType: 'arraybuffer' });
    const zipData = Buffer.from(response.data);

    // Extract the ZIP archive in memory
    const zip = new AdmZip(zipData);

    // List the files in the ZIP archive (optional)
    const zipEntries = zip.getEntries();
    zipEntries.forEach((entry) => {
      console.log(entry.entryName);
    });

    // Access and manipulate the files from the ZIP archive as needed
    // For example, to get the content of a file:
    const fileContents = zip.readAsText('repo-main-folder/your-file.txt');
    console.log(fileContents);
  } catch (error) {
    console.error('Error downloading or extracting the GitHub repo:', error);
  }
}

// Replace 'owner' and 'repo' with the GitHub repository owner and name you want to download
const owner = 'github_owner';
const repo = 'github_repo';

downloadAndExtractGitHubRepo(owner, repo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant