summaryrefslogtreecommitdiffhomepage
path: root/packages/console/app/src/lib/github.ts
blob: 49b9264635aed2a5e6c7c5afca30fd356bef2b00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { query } from "@solidjs/router"

export const github = query(async () => {
  "use server"
  try {
    const [meta, releases, contributors] = await Promise.all([
      fetch("https://api.github.com/repos/sst/opencode").then((res) => res.json()),
      fetch("https://api.github.com/repos/sst/opencode/releases").then((res) => res.json()),
      fetch("https://api.github.com/repos/sst/opencode/contributors?per_page=1"),
    ])
    const [release] = releases
    const contributorCount = Number.parseInt(
      contributors.headers
        .get("Link")!
        .match(/&page=(\d+)>; rel="last"/)!
        .at(1)!,
    )
    return {
      stars: meta.stargazers_count,
      release: {
        name: release.name,
        url: release.html_url,
      },
      contributors: contributorCount,
    }
  } catch {}
  return undefined
}, "github")