https://github.com/nikelborm/fetch-github-folder
Download any directory at any depth from any repo on GitHub on any git ref
https://github.com/nikelborm/fetch-github-folder
directory download downloader git github github-api javascript node node-js nodejs npm octokit octokit-js scraper script typescript
Last synced: about 2 months ago
JSON representation
Download any directory at any depth from any repo on GitHub on any git ref
- Host: GitHub
- URL: https://github.com/nikelborm/fetch-github-folder
- Owner: nikelborm
- License: mit
- Created: 2023-11-03T06:27:30.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-14T18:17:19.000Z (4 months ago)
- Last Synced: 2025-04-14T17:01:57.967Z (about 2 months ago)
- Topics: directory, download, downloader, git, github, github-api, javascript, node, node-js, nodejs, npm, octokit, octokit-js, scraper, script, typescript
- Language: TypeScript
- Homepage: https://nikelborm.github.io/fetch-github-folder/
- Size: 17 MB
- Stars: 4
- Watchers: 0
- Forks: 0
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
#
fetch-github-folder :lizard:
[](https://github.dev/nikelborm/fetch-github-folder)
[](https://www.npmjs.com/package/fetch-github-folder)
[](https://npmjs.org/package/fetch-github-folder)
[](https://npmjs.org/package/fetch-github-folder)
[](https://www.npmjs.com/package/fetch-github-folder?activeTab=dependencies)
[](https://www.npmjs.com/package/fetch-github-folder?activeTab=dependents)
[](https://jsr.io/@nikelborm/fetch-github-folder)
[](https://jsr.io/@nikelborm/fetch-github-folder)
[](https://jsr.io/@nikelborm)
[](https://github.com/nikelborm/fetch-github-folder/pulse)
[](https://github.com/nikelborm/fetch-github-folder/graphs/commit-activity)
[](https://github.com/nikelborm/fetch-github-folder?tab=MIT-1-ov-file)
[](https://coveralls.io/github/nikelborm/fetch-github-folder?branch=main)
[](https://www.codefactor.io/repository/github/nikelborm/fetch-github-folder)
[](https://codeclimate.com/github/nikelborm/fetch-github-folder/issues)
[](https://codeclimate.com/github/nikelborm/fetch-github-folder/issues)
[](https://github.com/nikelborm/fetch-github-folder/actions/workflows/test.yml)
[](https://github.com/nikelborm/fetch-github-folder/actions/workflows/release.yml)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
[](https://sonarcloud.io/summary/new_code?id=nikelborm_fetch-github-folder)
(Don't judge me for my obsession with badges)
> [!CAUTION]
>
> This project currently is not stable, but I'm actively working on writing tests and handling edge cases, such as support for Git-LFS and other.
> Check out the `dev` branch to see the latest updates! 😉 (except that I currently don't care and just push to main)## What This Project Does
This project allows you to download any folder inside a repo on github.
## Requirements
You need to have installed latest node, git, npm
## Installation
### From [default NPM registry](https://www.npmjs.com/package/fetch-github-folder)
```bash
npm i fetch-github-folder
```### From [JSR](https://jsr.io/@nikelborm/fetch-github-folder)
Unfortunately JSR doesn't support publishing executables yet, so you can install only script library with functions that will allow you to fetch github folder from other scripts.
```bash
npx jsr add @nikelborm/fetch-github-folder
```### From [GitHub's NPM registry](https://github.com/nikelborm/fetch-github-folder/pkgs/npm/fetch-github-folder)
1. [Generate `Personal access token (classic)` with `read:packages` scope](https://github.com/settings/tokens/new?description=Install%20packages%20from%20GitHub%20NPM%20registry&scopes=read:packages&default_expires_at=none)
2. Save the token
3. Login to Github's NPM registry (yes you need to do it, even if the package is public):```bash
npm login --scope=@nikelborm --auth-type=legacy --registry=https://npm.pkg.github.com
```You can also read more about `--auth-type=legacy` [here](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#authenticating-with-a-personal-access-token)
4. Enter your username when asked
5. Paste the token as password value
6. Then install the package by executing:```bash
npm i @nikelborm/fetch-github-folder
```### For local development
```bash
# Clone this repo:
git clone -b main https://github.com/nikelborm/fetch-github-folder.git
# cd to it:
cd fetch-github-folder
# Install dependencies:
npm install
# Create .env file:
cp template.env .env
# Ask for token
read -sp 'Enter github access token: ' gh_token; echo;
# And immediately put it into .env
sed -i "s/\(GITHUB_ACCESS_TOKEN\)='.*'/\1='$gh_token'/" .env
```## Environment Variables
- `GITHUB_ACCESS_TOKEN`: This is your personal access token from GitHub. It is used to authenticate your requests to the GitHub API. You can generate one [here](https://github.com/settings/tokens/new?description=Read%20repo%20contents%20access%20to%20fetch-github-folder&scopes=public_repo&default_expires_at=none).
- `REPO_OWNER`: This is the username of the owner of the repository you are trying to download from. For example, if the repository's URL is `https://github.com/apache/superset`, the owner is `apache`.
- `REPO_NAME`: This is the name of the repository you are trying to download from. In the example above, the repository name is `superset`.
- `PATH_TO_ENTITY_IN_REPO`: This is the path to the directory you want to download. It can be directory that lies inside root of repo like `docker` or it can be some nested directory like `docker/nginx`.
- `GIT_REF`: This is the commit SHA hash, branch name, or tag name you want to download from. If you don't specify it, the default branch in the repository will be used.
- `DESTINATION_PATH`: If entity at `PATH_TO_ENTITY_IN_REPO` is a file, then destination path is a path to downloaded file. If it's a directory, then all files and directories from target directory of remote repository at `PATH_TO_ENTITY_IN_REPO` will be put into a directory with path from `DESTINATION_PATH`. If the directory doesn't exist, it will be automatically created.## How to use
1. Set env variables in `.env` file
2. Run `npm start`