Created
June 25, 2023 01:22
-
-
Save EliasAfara/f22b3f6b3eeb5f281e4b391598cdd3be to your computer and use it in GitHub Desktop.
Fetch Github Repository Stars and Forks
This file contains hidden or 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
export async function getRepoStarsAndForks(owner, repo, token) { | |
const endpoint = `https://api.github.com/repos/${owner}/${repo}`; | |
const headers = { | |
Authorization: `Token ${token}`, | |
}; | |
try { | |
const response = await fetch(endpoint, { headers }); | |
const data = await response.json(); | |
return { | |
stars: data.stargazers_count, | |
forks: data.forks_count, | |
}; | |
} catch (error) { | |
console.error(error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment