diff --git a/__tests__/github.test.ts b/__tests__/github.test.ts index e6277ac4..c443f0f3 100644 --- a/__tests__/github.test.ts +++ b/__tests__/github.test.ts @@ -1,4 +1,7 @@ -import { getGitHubMetaWithFallback, getGitHubPublicFork } from '@/admin/github'; +import { + getGitHubMetaWithFallback, + getGitHubPublicFork, +} from '@/utility/github'; import { TEMPLATE_REPO_OWNER, TEMPLATE_REPO_NAME } from '@/app-core/config'; describe('GitHub', () => { @@ -8,7 +11,7 @@ describe('GitHub', () => { repo: TEMPLATE_REPO_NAME, }); expect(meta).toBeDefined(); - expect(meta.url).toBeDefined(); + expect(meta.urlRepo).toBeDefined(); expect(meta.isForkedFromBase).toEqual(false); expect(meta.label).toBeDefined(); expect(meta.description).toBeDefined(); @@ -26,7 +29,7 @@ describe('GitHub', () => { repo: 'nonexistent', }); expect(meta).toBeDefined(); - expect(meta.url).toBeDefined(); + expect(meta.urlRepo).toBeDefined(); expect(meta.isForkedFromBase).toEqual(false); expect(meta.label).toEqual('Unknown'); expect(meta.description).toEqual('Unknown'); @@ -38,7 +41,7 @@ describe('GitHub', () => { repo: 'bad text for a url.com', }); expect(meta).toBeDefined(); - expect(meta.url).toBeDefined(); + expect(meta.urlRepo).toBeDefined(); expect(meta.isForkedFromBase).toEqual(false); expect(meta.label).toEqual('Unknown'); expect(meta.description).toEqual('Unknown'); diff --git a/src/admin/github/GitHubForkStatusBadge.tsx b/src/admin/github/GitHubForkStatusBadge.tsx deleted file mode 100644 index 6faf63ef..00000000 --- a/src/admin/github/GitHubForkStatusBadge.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { Suspense } from 'react'; -import GitHubForkStatusBadgeClient from './GitHubForkStatusBadgeClient'; -import GitHubForkStatusBadgeServer from './GitHubForkStatusBadgeServer'; -import { IS_DEVELOPMENT } from '@/app-core/config'; - -export default function GitHubForkStatusBadge() { - return IS_DEVELOPMENT - ? - : - - ; -} diff --git a/src/admin/github/GitHubForkStatusBadgeClient.tsx b/src/admin/github/GitHubForkStatusBadgeClient.tsx deleted file mode 100644 index 45a79750..00000000 --- a/src/admin/github/GitHubForkStatusBadgeClient.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import Spinner from '@/components/Spinner'; -import Tooltip from '@/components/Tooltip'; -import clsx from 'clsx/lite'; -import { ReactNode } from 'react'; -import { BiLogoGithub } from 'react-icons/bi'; - -export default function GitHubForkStatusBadgeClient({ - label, - style = 'mono', - tooltip, -}: { - label?: ReactNode - style?: 'info' |'success' | 'warning' | 'error' | 'mono' - tooltip?: ReactNode -}) { - const classNameForStyle = () => { - switch (style) { - case 'info': return clsx( - 'text-blue-600 hover:text-blue-600', - 'dark:text-blue-400 dark:hover:text-blue-400', - 'bg-blue-100/40 dark:bg-blue-900/25', - 'border-blue-300/40 dark:border-blue-900/50', - ); - case 'success': return clsx( - 'text-green-700 hover:text-green-700', - 'dark:text-green-400 dark:hover:text-green-400', - 'bg-green-100/40 dark:bg-green-900/25', - 'border-green-300/40 dark:border-green-900/50', - ); - case 'warning': return clsx( - 'text-amber-800/90 hover:text-amber-800/90', - 'dark:text-amber-400 dark:hover:text-amber-400', - 'bg-amber-100/40 dark:bg-amber-900/25', - 'border-amber-300/40 dark:border-amber-900/50', - ); - case 'error': return clsx( - 'text-red-700/90 hover:text-red-700/90', - 'dark:text-red-400 dark:hover:text-red-400', - 'bg-red-100/20 dark:bg-red-900/25', - 'border-red-300/40 dark:border-red-900/50', - ); - default: return clsx( - 'text-main', - 'bg-white dark:bg-transparent', - 'border-main', - ); - } - }; - - return ( - -
- {!label - ? - : } - {label ?? 'Checking'} -
-
- ); -} diff --git a/src/admin/github/GitHubForkStatusBadgeServer.tsx b/src/admin/github/GitHubForkStatusBadgeServer.tsx deleted file mode 100644 index ab49eaca..00000000 --- a/src/admin/github/GitHubForkStatusBadgeServer.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import GitHubForkStatusBadgeClient from './GitHubForkStatusBadgeClient'; -import { - VERCEL_GIT_BRANCH, - VERCEL_GIT_REPO_OWNER, - VERCEL_GIT_REPO_SLUG, - VERCEL_GIT_COMMIT_SHA, -} from '@/app-core/config'; -import { getGitHubMetaWithFallback, getGitHubUrlRepo } from '.'; - -export default async function GitHubForkStatusBadgeServer() { - const owner = VERCEL_GIT_REPO_OWNER; - const repo = VERCEL_GIT_REPO_SLUG; - const branch = VERCEL_GIT_BRANCH; - const commit = VERCEL_GIT_COMMIT_SHA; - - const { - isForkedFromBase, - isBaseRepo, - isBehind, - label, - description, - didError, - } = await getGitHubMetaWithFallback({ owner, repo, branch, commit }); - - const repoLink = (text: string) => - - {text} - ; - - const isBehindContent = <> - {' '} - {repoLink('Sync on GitHub')} for latest updates. - ; - - const didErrorContent = <> - {' '} - Could not connect to {repoLink('GitHub')}. - ; - - return isForkedFromBase || isBaseRepo - ? - {description} - {didError - ? didErrorContent - : isBehind - ? isBehindContent - : null} - , - style: didError || isBehind === undefined || isBehind - ? 'info' - : 'mono', - }} /> - : null; -} diff --git a/src/admin/insights/AdminAppInsights.tsx b/src/admin/insights/AdminAppInsights.tsx index c951ce77..b32f1577 100644 --- a/src/admin/insights/AdminAppInsights.tsx +++ b/src/admin/insights/AdminAppInsights.tsx @@ -18,7 +18,7 @@ import { VERCEL_GIT_REPO_OWNER, VERCEL_GIT_REPO_SLUG, } from '@/app-core/config'; -import { getGitHubMetaWithFallback } from '../github'; +import { getGitHubMetaWithFallback } from '../../utility/github'; import { OUTDATED_THRESHOLD } from '@/photo'; const BASIC_PHOTO_INSTALLATION_COUNT = 32; diff --git a/src/admin/insights/AdminAppInsightsClient.tsx b/src/admin/insights/AdminAppInsightsClient.tsx index 6b78f7bb..d2fe111f 100644 --- a/src/admin/insights/AdminAppInsightsClient.tsx +++ b/src/admin/insights/AdminAppInsightsClient.tsx @@ -11,7 +11,7 @@ import { HiOutlinePhotograph } from 'react-icons/hi'; import { MdAspectRatio } from 'react-icons/md'; import { PiWarningBold } from 'react-icons/pi'; import { TbCone, TbSparkles } from 'react-icons/tb'; -import { getGitHubMetaWithFallback } from '../github'; +import { getGitHubMetaWithFallback } from '../../utility/github'; import { BiGitBranch, BiGitCommit, BiLogoGithub } from 'react-icons/bi'; import { TEMPLATE_REPO_BRANCH, diff --git a/src/app/admin/insights/page.tsx b/src/app/admin/insights/page.tsx index e81b4596..0bf5efa4 100644 --- a/src/app/admin/insights/page.tsx +++ b/src/app/admin/insights/page.tsx @@ -1,17 +1,8 @@ import AdminAppInsights from '@/admin/insights/AdminAppInsights'; import AdminInfoPage from '@/admin/AdminInfoPage'; -import GitHubForkStatusBadge from '@/admin/github/GitHubForkStatusBadge'; -import { - IS_DEVELOPMENT, - IS_VERCEL_GIT_PROVIDER_GITHUB, -} from '@/app-core/config'; export default async function AdminInsightsPage() { - return } - > + return ; } diff --git a/src/admin/github/index.ts b/src/utility/github.ts similarity index 96% rename from src/admin/github/index.ts rename to src/utility/github.ts index 58208bbc..c2ed6d75 100644 --- a/src/admin/github/index.ts +++ b/src/utility/github.ts @@ -121,14 +121,12 @@ const isRepoBaseRepo = ({ owner, repo }: RepoParams) => owner?.toLowerCase() === TEMPLATE_REPO_OWNER && repo?.toLowerCase() === TEMPLATE_REPO_NAME; -export const getGitHubPublicFork = async ( - params?: RepoParams, -): Promise => { - const response = await fetch(getGitHubApiForksUrl(params), FETCH_CONFIG); +export const getGitHubPublicFork = async (): Promise => { + const response = await fetch(getGitHubApiForksUrl(), FETCH_CONFIG); const fork = (await response.json())[0]; return { - owner: fork.owner.login, - repo: fork.name, + owner: fork?.owner.login, + repo: fork?.name, }; };