github.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { query } from "@solidjs/router"
  2. export const github = query(async () => {
  3. "use server"
  4. try {
  5. const [meta, releases, contributors] = await Promise.all([
  6. fetch("https://api.github.com/repos/sst/opencode").then(async (res) => {
  7. const text = await res.text()
  8. console.log(text)
  9. const json = JSON.parse(text)
  10. return json
  11. }),
  12. fetch("https://api.github.com/repos/sst/opencode/releases").then(async (res) => {
  13. const text = await res.text()
  14. console.log(text)
  15. const json = JSON.parse(text)
  16. return json
  17. }),
  18. fetch("https://api.github.com/repos/sst/opencode/contributors?per_page=1"),
  19. ])
  20. const [release] = releases
  21. const contributorCount = Number.parseInt(
  22. contributors.headers
  23. .get("Link")!
  24. .match(/&page=(\d+)>; rel="last"/)!
  25. .at(1)!,
  26. )
  27. return {
  28. stars: meta.stargazers_count,
  29. release: {
  30. name: release.name,
  31. url: release.html_url,
  32. },
  33. contributors: contributorCount,
  34. }
  35. } catch (e) {
  36. console.error(e)
  37. }
  38. return undefined
  39. }, "github")