Files
supabase/apps/studio/pages/api/cli-release-version.ts
T
Han QiaoandJoshen Lim 698e585a65 feat: fetch beta cli release version (#34923)
* feat: fetch beta cli release version

* Small refactors

* Fix

* Fix

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-04-14 16:20:03 +08:00

34 lines
926 B
TypeScript

import { NextApiRequest, NextApiResponse } from 'next'
type GitHubRepositoryRelease = {
id: number
url: string
name: string
tag_name: string
published_at: string
}
const current = process.env.CURRENT_CLI_VERSION
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
try {
const { tag_name: latest, published_at }: GitHubRepositoryRelease = await fetch(
'https://api.github.com/repos/supabase/cli/releases/latest'
).then((res) => res.json())
const data: GitHubRepositoryRelease[] = await fetch(
'https://api.github.com/repos/supabase/cli/releases?per_page=1'
)
.then((res) => res.json())
// Ignore errors fetching beta release version
.catch(() => [])
const beta = data[0]?.tag_name
return res.status(200).json({ current, latest, beta, published_at })
} catch {
return res.status(200).json({ current })
}
}
export default handler