github.ts 879 B

123456789101112131415161718192021222324252627282930
  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((res) => res.json()),
  7. fetch("https://api.github.com/repos/sst/opencode/releases").then((res) => res.json()),
  8. fetch("https://api.github.com/repos/sst/opencode/contributors?per_page=1"),
  9. ])
  10. const [release] = releases
  11. const contributorCount = Number.parseInt(
  12. contributors.headers
  13. .get("Link")!
  14. .match(/&page=(\d+)>; rel="last"/)!
  15. .at(1)!,
  16. )
  17. return {
  18. stars: meta.stargazers_count,
  19. release: {
  20. name: release.name,
  21. url: release.html_url,
  22. },
  23. contributors: contributorCount,
  24. }
  25. } catch (e) {
  26. console.error(e)
  27. }
  28. return undefined
  29. }, "github")