Skip to content

Commit

Permalink
feat: support the case where there is no latest release
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiteMinds committed Oct 26, 2023
1 parent 293d11b commit 226497a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
3 changes: 3 additions & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,8 @@
},
"ct3aMetadata": {
"initVersion": "7.5.9"
},
"peerDependencies": {
"@octokit/request-error": "*"
}
}
8 changes: 4 additions & 4 deletions packages/app/src/pages/download/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { Assets } from './Assets'
import { useIsMobile } from '../../hooks'

interface PageProps {
release: Release
release: Release | null
}

const Download: NextPage<PageProps> = ({ release }) => {
const { t } = useTranslation('download')
const isMobile = useIsMobile()

const assets = useMemo(() => getAssetsFromNeuronRelease(release), [release])
const assets = useMemo(() => (release ? getAssetsFromNeuronRelease(release) : []), [release])

return (
<Page className={styles.page}>
Expand All @@ -34,7 +34,7 @@ const Download: NextPage<PageProps> = ({ release }) => {

{!isMobile && (
<div className={styles.version}>
{t('Current Version')} {release.tag_name}
{t('Current Version')} {release?.tag_name}
</div>
)}
</div>
Expand All @@ -46,7 +46,7 @@ const Download: NextPage<PageProps> = ({ release }) => {

{isMobile && (
<div className={styles.version}>
{t('Current Version')} {release.tag_name}
{t('Current Version')} {release?.tag_name}
</div>
)}

Expand Down
9 changes: 6 additions & 3 deletions packages/app/src/pages/home/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { ParsedAsset, Release, getAssetsFromNeuronRelease, getLatestRelease } fr

interface PageProps {
locale: string
release: Release
release: Release | null
}

const Home: NextPage<PageProps> = ({ locale, release }) => {
Expand Down Expand Up @@ -121,9 +121,12 @@ const Emphasis: FC<PropsWithChildren> = ({ children }) => (
</span>
)

const DownloadButton: FC<Partial<ComponentProps<typeof Link>> & { release: Release }> = ({ release, ...linkProps }) => {
const DownloadButton: FC<Partial<ComponentProps<typeof Link>> & { release: Release | null }> = ({
release,
...linkProps
}) => {
const { t } = useTranslation('home')
const assets = useMemo(() => getAssetsFromNeuronRelease(release), [release])
const assets = useMemo(() => (release ? getAssetsFromNeuronRelease(release) : []), [release])
const [asset, setAsset] = useState<ParsedAsset>()

useEffect(() => {
Expand Down
20 changes: 14 additions & 6 deletions packages/app/src/utils/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Repository,
SearchResultItemConnection,
} from '@octokit/graphql-schema'
import { RequestError } from '@octokit/request-error'
import { BooleanT } from './array'
import { REPO, TOKEN } from './env'

Expand Down Expand Up @@ -218,12 +219,19 @@ export async function getReleases(limit = Infinity): Promise<Release[]> {
return releases.slice(0, limit)
}

export async function getLatestRelease(): Promise<Release> {
const res = await octokit.rest.repos.getLatestRelease({
owner: repoOwner,
repo: repoName,
})
return res.data
export async function getLatestRelease(): Promise<Release | null> {
try {
const res = await octokit.rest.repos.getLatestRelease({
owner: repoOwner,
repo: repoName,
})
return res.data
} catch (err) {
if (err instanceof RequestError && err.status === 404) {
return null
}
throw err
}
}

export function getAssetsFromNeuronRelease(neuronRelease: Release): ParsedAsset[] {
Expand Down
2 changes: 2 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4019,6 +4019,8 @@ __metadata:
typescript: ^5.1.3
ua-parser-js: ^1.0.35
zod: ^3.21.4
peerDependencies:
"@octokit/request-error": "*"
languageName: unknown
linkType: soft

Expand Down

0 comments on commit 226497a

Please sign in to comment.