| 6 | let starCount: number | undefined = undefined; |
| 7 | |
| 8 | export async function countStars( |
| 9 | repo = 'shipshapecode/shepherd' |
| 10 | ): Promise<number> { |
| 11 | if (starCount) { |
| 12 | return starCount; |
| 13 | } |
| 14 | |
| 15 | try { |
| 16 | const repoData = await fetch(`https://api.github.com/repos/${repo}`); |
| 17 | const json = await repoData.json(); |
| 18 | |
| 19 | starCount = json.stargazers_count * 1 || defaultStarCount; |
| 20 | } catch (e) { |
| 21 | console.log('Failed to fetch stars', e); |
| 22 | starCount = defaultStarCount; |
| 23 | } |
| 24 | |
| 25 | return starCount; |
| 26 | } |
| 27 | |
| 28 | export async function getFormattedStars( |
| 29 | repo = 'shipshapecode/shepherd' |