Skip to content

Instantly share code, notes, and snippets.

@wolfiex
Last active August 2, 2023 06:57
Show Gist options
  • Save wolfiex/2632b36250600d193108c044cc6d3b24 to your computer and use it in GitHub Desktop.
Save wolfiex/2632b36250600d193108c044cc6d3b24 to your computer and use it in GitHub Desktop.
Fetch files from github.
/* Author: Daniel Ellis 2022 */
export async function getgit (owner, repo, path) {
// A function to fetch files from github using the api
let data = await fetch (
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`
)
.then (d => d.json ())
.then (d =>
fetch (
`https://api.github.com/repos/${owner}/${repo}/git/blobs/${d.sha}`
)
)
.then (d => d.json ())
.then (d => JSON.parse (atob (d.content)));
return data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment