Compare commits

...
4 changed files with 52 additions and 5 deletions
+6 -1
View File
@@ -24,11 +24,16 @@ jobs:
- name: Run stats script
run: bun script/stats.ts
- name: Update GitHub stars
run: bun script/update-github-stars.ts
env:
GITHUB_TOKEN: ${{ github.token }}
- name: Commit stats
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add STATS.md
git add STATS.md packages/console/app/src/config.ts packages/stats/app/src/routes/stats-shell.tsx
git diff --staged --quiet || git commit -m "ignore: update download stats $(date -I)"
git push
env:
+2 -2
View File
@@ -9,8 +9,8 @@ export const config = {
github: {
repoUrl: "https://github.com/anomalyco/opencode",
starsFormatted: {
compact: "205K",
full: "205,000",
compact: "207K",
full: "207,000",
},
},
@@ -10,7 +10,7 @@ export type HeaderLink = { href: string; label: string }
export const githubLink = {
href: "https://github.com/anomalyco/opencode",
apiHref: "https://api.github.com/repos/anomalyco/opencode",
fallbackStars: "205K",
fallbackStars: "207K",
}
export const themePreferences = ["dark", "light", "system"] as const
export const themeStorageKey = "opencode:stats-theme"
@@ -19,7 +19,6 @@ export type ThemePreference = (typeof themePreferences)[number]
const compactNumberFormatter = new Intl.NumberFormat("en", {
notation: "compact",
maximumFractionDigits: 0,
roundingIncrement: 5,
})
export const getGitHubStars = query(async () => {
+43
View File
@@ -0,0 +1,43 @@
#!/usr/bin/env bun
const response = await fetch("https://api.github.com/repos/anomalyco/opencode", {
headers: {
Accept: "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28",
...(process.env.GITHUB_TOKEN ? { Authorization: `Bearer ${process.env.GITHUB_TOKEN}` } : {}),
},
})
if (!response.ok) throw new Error(`GitHub API error: ${response.status} ${response.statusText}`)
const body: unknown = await response.json()
if (!body || typeof body !== "object" || !("stargazers_count" in body) || typeof body.stargazers_count !== "number")
throw new Error("GitHub API response did not include a star count")
const compact = new Intl.NumberFormat("en", {
notation: "compact",
maximumFractionDigits: 0,
}).format(body.stargazers_count)
const full = new Intl.NumberFormat("en").format(Math.round(body.stargazers_count / 1_000) * 1_000)
const statsFile = "packages/stats/app/src/routes/stats-shell.tsx"
const statsContent = await Bun.file(statsFile).text()
const statsPattern = /fallbackStars: "[^"]+"/
if (!statsPattern.test(statsContent)) throw new Error(`GitHub star fallback not found in ${statsFile}`)
const siteFile = "packages/console/app/src/config.ts"
const siteContent = await Bun.file(siteFile).text()
const compactPattern = /compact: "[^"]+"/
const fullPattern = /full: "[^"]+"/
if (!compactPattern.test(siteContent) || !fullPattern.test(siteContent))
throw new Error(`GitHub star fallbacks not found in ${siteFile}`)
await Promise.all([
Bun.write(statsFile, statsContent.replace(statsPattern, `fallbackStars: "${compact}"`)),
Bun.write(
siteFile,
siteContent.replace(compactPattern, `compact: "${compact}"`).replace(fullPattern, `full: "${full}"`),
),
])
console.log(`Updated GitHub star fallbacks to ${compact} (${full})`)