Skip to content

Commit

Permalink
more resilient release fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
goodroot committed Nov 22, 2024
1 parent 99c6615 commit 20ab8a9
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions plugins/fetch-latest-release/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export type Release = {
html_url?: string
}

export async function fetchLatestRelease(): Promise<Release | null> {
const DEFAULT_RELEASE: Release = {
name: 'latest',
html_url: 'https://github.com/questdb/questdb/releases/latest'
}

export async function fetchLatestRelease(): Promise<Release> {
if (typeof fetch === 'undefined') {
try {
const response = await nodeFetch('https://github-api.questdb.io/github/latest', {
Expand All @@ -17,14 +22,14 @@ export async function fetchLatestRelease(): Promise<Release | null> {

if (!response.ok) {
console.error(`GitHub API error: ${response.status}`)
return null
return DEFAULT_RELEASE
}

const data = await response.json()
return data
} catch (error) {
console.error('Failed to fetch latest release:', error)
return null
return DEFAULT_RELEASE
}
}

Expand All @@ -36,14 +41,14 @@ export async function fetchLatestRelease(): Promise<Release | null> {

if (!response.ok) {
console.error(`GitHub API error: ${response.status}`)
return null
return DEFAULT_RELEASE
}

const data = await response.json()
return data
} catch (error) {
console.error('Failed to fetch latest release:', error)
return null
return DEFAULT_RELEASE
}
}

Expand All @@ -55,7 +60,7 @@ export default function plugin(): Plugin {
},
async contentLoaded({ content, actions }) {
const { setGlobalData } = actions
setGlobalData({ latestRelease: content })
setGlobalData({ release: content })
},
}
}

0 comments on commit 20ab8a9

Please sign in to comment.