Skip to content

Instantly share code, notes, and snippets.

@EliasAfara
Created June 25, 2023 01:22
Show Gist options
  • Save EliasAfara/f22b3f6b3eeb5f281e4b391598cdd3be to your computer and use it in GitHub Desktop.
Save EliasAfara/f22b3f6b3eeb5f281e4b391598cdd3be to your computer and use it in GitHub Desktop.
Fetch Github Repository Stars and Forks
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