-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
75 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ | |
"vitest": "^0.34.6", | ||
"yargs-parser": "^21.1.1" | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import fetch from 'node-fetch' | ||
|
||
const api = async (endpoint: string) => { | ||
const response = await fetch(`https://api.github.com/repos/${endpoint}`) | ||
const contents = (await response.json()) as | ||
| { message: string } | ||
| { type: string; path: string }[] | ||
return contents | ||
} | ||
|
||
type Options = { | ||
user: string | ||
repository: string | ||
ref: string | ||
directory: string | ||
} | ||
|
||
export const viaContentsApi = async ({ | ||
user, | ||
repository, | ||
ref = 'HEAD', | ||
directory, | ||
}: Options) => { | ||
const files = [] | ||
const contents = await api( | ||
`${user}/${repository}/contents/${directory}?ref=${ref}` | ||
) | ||
|
||
if ('message' in contents) { | ||
if (contents.message === 'Not Found') { | ||
return [] | ||
} | ||
if (contents.message) { | ||
throw new Error(contents.message) | ||
} | ||
} | ||
|
||
if (Array.isArray(contents)) { | ||
for (const item of contents) { | ||
if (item.type === 'file') { | ||
files.push(item.path) | ||
} else if (item.type === 'dir') { | ||
files.push(item.path) | ||
} | ||
} | ||
} | ||
|
||
return files | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"types": [ | ||
"node" | ||
], | ||
"lib": [ | ||
"esnext" | ||
], | ||
}, | ||
} |