Skip to content

Commit d4e2e40

Browse files
authored
Merge pull request #10 from sauravhathi/dev
new feature ⚡ useGitHubFolderDownload
2 parents f2b418a + 818883b commit d4e2e40

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2543
-236
lines changed

README.md

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# GitHub Folder Tree 🌲
22

3-
**github-folder-tree** is a React custom hook that allows you to fetch and process the contents of a GitHub folder. It retrieves information about the files and subfolders in the specified folder, including their names, file types, download URLs, SHA hashes, sizes, and paths.
3+
**github-folder-tree** is a React custom hook that allows you to fetch and process the contents of a GitHub folder. It retrieves information about the files and subfolders in the specified folder, including their names, file types, download URLs, SHA hashes, sizes, and paths. In addition, it provides the functionality to download the contents of the folder as a ZIP file and access repository information.
44

55
## Installation ⬇️
66

@@ -25,29 +25,39 @@ import {useGitHubFolderTree} from 'github-folder-tree';
2525
**repositoryUrl** is the URL of the GitHub repository, and **apiKey** is an optional GitHub API key for authentication.
2626

2727
```jsx
28-
const { repoFiles, error, log, fetchRepositoryContents } = useGitHubFolderTree(repositoryUrl, apiKey);
28+
const { repoFiles, error, log, fetchRepositoryContents, useGitHubFolderDownload, repoInfo } = useGitHubFolderTree(folderUrl, apiKey);
2929
```
3030

3131
### Example
3232

3333
```javascript
34-
import { useState } from 'react';
35-
import {useGitHubFolderTree} from 'github-folder-tree';
34+
import React, { FC, useState } from 'react';
35+
import useGitHubFolderTree from './hooks/useGitHubFolderTree';
3636

3737
const MyComponent = () => {
38-
const [repositoryUrl, setRepositoryUrl] = useState('');
38+
const [folderUrl, setFolderUrl] = useState('');
3939
const [apiKey, setApiKey] = useState('');
40-
const { repoFiles, error, log, fetchRepositoryContents } = useGitHubFolderTree(repositoryUrl, apiKey);
40+
const { repoFiles, error, log, fetchRepositoryContents, useGitHubFolderDownload, repoInfo } = useGitHubFolderTree(folderUrl, apiKey);
4141

4242
const handleFetchClick = () => {
4343
fetchRepositoryContents();
4444
};
4545

46+
const handleDownloadClick = () => {
47+
useGitHubFolderDownload();
48+
};
49+
50+
if (repoFiles.length > 0) {
51+
console.log(repoFiles);
52+
console.log(repoInfo);
53+
}
54+
4655
return (
4756
<div>
48-
<input type="text" value={repositoryUrl} onChange={(e) => setRepositoryUrl(e.target.value)} placeholder="Enter GitHub repository URL" />
57+
<input type="text" value={folderUrl} onChange={(e) => setFolderUrl(e.target.value)} placeholder="Enter GitHub folder URL" />
4958
<input type="text" value={apiKey} onChange={(e) => setApiKey(e.target.value)} placeholder="Enter GitHub API key (optional)" />
5059
<button onClick={handleFetchClick}>Fetch Folder Contents</button>
60+
<button onClick={handleDownloadClick}>Download Folder as ZIP</button>
5161
{error && <div>Error: {error}</div>}
5262
{log && <div>Log: {log}</div>}
5363
<table>
@@ -77,7 +87,11 @@ const MyComponent = () => {
7787
export default MyComponent;
7888
```
7989

80-
In the above example, **repositoryUrl** is the URL of the GitHub repository, and **apiKey** is an optional GitHub API key for authentication.
90+
In the above example, **folderUrl** is the URL of the GitHub folder, and **apiKey** is an optional GitHub API key for authentication.
91+
92+
To fetch the contents of a GitHub folder, enter the folder URL in the input field and click **Fetch Folder Contents**. The files and their details will be displayed in a table. Any errors or log messages will be shown accordingly.
93+
94+
To download the folder as a ZIP file, click the **Download Folder as ZIP** button. The ZIP file will be generated and downloaded.
8195

8296
To fetch the contents of the root folder of a repository, use the repository URL in the following format:
8397

@@ -109,14 +123,14 @@ Note: Make sure to handle any errors and display them appropriately in your Reac
109123

110124
#### X-Ratelimit-Limit: 60
111125

112-
<img src="https://github.com/sauravhathi/github-folder-tree/assets/61316762/a0896f79-da0e-43af-a7db-230ad27fa5a4" alt="image" width="500px" height="auto" />
126+
<img src="https://github.com/sauravhathi/github-folder-tree/assets/61316762/de10a672-ef74-4388-837d-d165368ec640" alt="image" width="500px" height="auto" />
113127

114128
#### API rate limit exceeded
115-
<img src="https://github.com/sauravhathi/github-folder-tree/assets/61316762/6193d3e7-978c-4c66-b54d-26bf582c2cdb" alt="image" width="500px" height="auto" />
129+
<img src="https://github.com/sauravhathi/github-folder-tree/assets/61316762/5dcd4868-8e2e-4b10-8fd9-a8af788f412d" alt="image" width="500px" height="auto" />
116130

117131
#### Using Github API Key(Personal access tokens) - X-Ratelimit-Limit: 5000
118132

119-
<img src="https://github.com/sauravhathi/github-folder-tree/assets/61316762/38c7453c-b920-446e-90e3-9f41bd7df542" alt="image" width="500px" height="auto" />
133+
<img src="https://github.com/sauravhathi/github-folder-tree/assets/61316762/db552e41-c41d-44b7-b010-4e24a86a6388" alt="image" width="500px" height="auto" />
120134

121135
## Hook Reference 📚
122136

@@ -128,6 +142,9 @@ The **useGitHubFolderTree** hook returns the following values:
128142
| **error** | **string** | An error message if an error occurred during the fetch. |
129143
| **log** | **string** | Log messages for tracking progress and debugging. |
130144
| **fetchRepositoryContents** | **function** | A function that fetches the contents of the specified GitHub folder. |
145+
| **useGitHubFolderDownload** | **function** | A function that downloads the contents of the specified GitHub folder as a ZIP file. |
146+
| **repoInfo** | **RepoInfo** | An object containing information about the GitHub repository. |
147+
131148

132149
## Contributing 🤝
133150

@@ -159,4 +176,4 @@ If you have any questions or need further assistance, feel free to reach out to
159176

160177
## License
161178

162-
This project is licensed under the [MIT License](https://github.com/sauravhathi/github-folder-tree/blob/master/LICENSE).
179+
This project is licensed under the [MIT License](https://github.com/sauravhathi/github-folder-tree/blob/master/LICENSE).
+4-12
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
interface RepoFile {
2-
url: string;
3-
name: string;
4-
file_type: string;
5-
download_url: string;
6-
sha: string;
7-
size: string;
8-
path: string;
9-
type?: string;
10-
}
1+
import { RepoFile, RepoInfo } from '../types';
112
export declare const useGitHubFolderTree: (folderUrl: string, apiKey?: string) => {
123
repoFiles: RepoFile[];
4+
fetchRepositoryContents: () => Promise<void>;
5+
useGitHubFolderDownload: () => Promise<void>;
136
error: string;
147
log: string;
15-
fetchRepositoryContents: () => Promise<void>;
8+
repoInfo: RepoInfo;
169
};
17-
export {};

dist/cjs/hooks/useGitHubFolderTree.js

+36-58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/hooks/useGitHubFolderTree.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
export * from './hooks';
2+
export * from './types';
3+
export * from './utils';

dist/cjs/index.js

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/types/RepoFile.d.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export interface RepoFile {
2+
url: string;
3+
name: string;
4+
file_type: string;
5+
download_url: string;
6+
sha: string;
7+
size: string;
8+
path: string;
9+
type?: string;
10+
}

dist/cjs/types/RepoFile.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/types/RepoFile.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/types/RepoInfo.d.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export interface RepoInfo {
2+
user: string;
3+
repo: string;
4+
branch: string;
5+
dir: string;
6+
}

dist/cjs/types/RepoInfo.js

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/cjs/types/RepoInfo.js.map

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)