(repo: string)
| 1 | export const getRepoStars = async (repo: string) => { |
| 2 | const isGithub = repo.startsWith("https://github.com/"); |
| 3 | if (!isGithub) { |
| 4 | return undefined; |
| 5 | } |
| 6 | |
| 7 | const url = new URL(repo); |
| 8 | url.hostname = "api.github.com"; |
| 9 | url.pathname = `/repos${url.pathname}`; |
| 10 | console.log(url.toString()); |
| 11 | try { |
| 12 | const data = await (await fetch(url)).json(); |
| 13 | console.log(data.stargazers_count); |
| 14 | return data.stargazers_count; |
| 15 | } catch (error) { |
| 16 | console.error(error); |
| 17 | return undefined; |
| 18 | } |
| 19 | }; |