From 843c7046b26f154da1b1f7dd1a96a2ecb41e80a3 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Thu, 30 Jan 2025 10:02:43 -0600 Subject: [PATCH] Add for status to app configuration --- src/site/SiteChecklistClient.tsx | 23 ++++++++++++++++------- src/site/SiteChecklistServer.tsx | 13 ++++++++++++- src/site/config.ts | 15 ++++++++------- src/utility/git.ts | 8 -------- src/utility/github.ts | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 23 deletions(-) delete mode 100644 src/utility/git.ts create mode 100644 src/utility/github.ts diff --git a/src/site/SiteChecklistClient.tsx b/src/site/SiteChecklistClient.tsx index 96533fa0..38b8ec37 100644 --- a/src/site/SiteChecklistClient.tsx +++ b/src/site/SiteChecklistClient.tsx @@ -94,6 +94,8 @@ export default function SiteChecklistClient({ storageError, kvError, aiError, + // Git Meta + isForkedFromBaseRepo, // Component props simplifiedView, isTestingConnections, @@ -101,6 +103,8 @@ export default function SiteChecklistClient({ Partial>> & { simplifiedView?: boolean isTestingConnections?: boolean +} & { + isForkedFromBaseRepo?: boolean }) { const renderLink = (href: string, text: string, external = true) => <> @@ -665,13 +669,18 @@ export default function SiteChecklistClient({    {commitSha ? commitUrl - ? - {commitSha} - + ? <> + + {commitSha} + +   + {isForkedFromBaseRepo && + Forked} + : {commitSha} : 'Not Found'} diff --git a/src/site/SiteChecklistServer.tsx b/src/site/SiteChecklistServer.tsx index af73d43b..160be58d 100644 --- a/src/site/SiteChecklistServer.tsx +++ b/src/site/SiteChecklistServer.tsx @@ -1,6 +1,11 @@ import SiteChecklistClient from './SiteChecklistClient'; -import { CONFIG_CHECKLIST_STATUS } from '@/site/config'; +import { + CONFIG_CHECKLIST_STATUS, + VERCEL_GIT_REPO_OWNER, + VERCEL_GIT_REPO_SLUG, +} from '@/site/config'; import { testConnectionsAction } from '@/admin/actions'; +import { isRepoForkedFromBase } from '@/utility/github'; export default async function SiteChecklistServer({ simplifiedView, @@ -8,10 +13,16 @@ export default async function SiteChecklistServer({ simplifiedView?: boolean }) { const connectionErrors = await testConnectionsAction().catch(() => ({})); + const isForkedFromBaseRepo = await isRepoForkedFromBase( + VERCEL_GIT_REPO_OWNER, + VERCEL_GIT_REPO_SLUG, + ); + return ( ); diff --git a/src/site/config.ts b/src/site/config.ts index 14caa427..f47ff042 100644 --- a/src/site/config.ts +++ b/src/site/config.ts @@ -14,20 +14,21 @@ export const SITE_TITLE = 'Photo Blog'; // SOURCE -const VERCEL_GIT_PROVIDER = +export const VERCEL_GIT_PROVIDER = process.env.NEXT_PUBLIC_VERCEL_GIT_PROVIDER; -const VERCEL_GIT_REPO_OWNER = +export const VERCEL_GIT_REPO_OWNER = process.env.NEXT_PUBLIC_VERCEL_GIT_REPO_OWNER; -const VERCEL_GIT_REPO_SLUG = +export const VERCEL_GIT_REPO_SLUG = process.env.NEXT_PUBLIC_VERCEL_GIT_REPO_SLUG; -const VERCEL_GIT_COMMIT_MESSAGE = +export const VERCEL_GIT_COMMIT_MESSAGE = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_MESSAGE; -const VERCEL_GIT_COMMIT_SHA = +export const VERCEL_GIT_COMMIT_SHA = process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA; -const VERCEL_GIT_COMMIT_SHA_SHORT = VERCEL_GIT_COMMIT_SHA +export const VERCEL_GIT_COMMIT_SHA_SHORT = VERCEL_GIT_COMMIT_SHA ? VERCEL_GIT_COMMIT_SHA.slice(0, 7) : undefined; -const VERCEL_GIT_COMMIT_URL = VERCEL_GIT_PROVIDER === 'github' +export const VERCEL_IS_PROVIDER_GITHUB = VERCEL_GIT_PROVIDER === 'github'; +export const VERCEL_GIT_COMMIT_URL = VERCEL_IS_PROVIDER_GITHUB // eslint-disable-next-line max-len ? `https://github.com/${VERCEL_GIT_REPO_OWNER}/${VERCEL_GIT_REPO_SLUG}/commit/${VERCEL_GIT_COMMIT_SHA}` : undefined; diff --git a/src/utility/git.ts b/src/utility/git.ts deleted file mode 100644 index 97c32e71..00000000 --- a/src/utility/git.ts +++ /dev/null @@ -1,8 +0,0 @@ -const GITHUB_API_URL = - 'https://api.github.com/repos/sambecker/exif-photo-blog/commits/main'; - -export const fetchLatestRepoCommit = async () => { - const response = await fetch(GITHUB_API_URL); - const data = await response.json(); - return data.sha.slice(0, 7); -}; diff --git a/src/utility/github.ts b/src/utility/github.ts new file mode 100644 index 00000000..53201909 --- /dev/null +++ b/src/utility/github.ts @@ -0,0 +1,32 @@ +import { VERCEL_IS_PROVIDER_GITHUB } from '@/site/config'; + +const BASE_OWNER = 'sambecker'; +const BASE_REPO = 'exif-photo-blog'; + +type RepoParams = Parameters<(owner?: string, repo?: string) => unknown>; + +const getRepoUrl = (owner = BASE_OWNER, repo = BASE_REPO) => + `https://api.github.com/repos/${owner}/${repo}`; + +const getCommitsUrl = (...args: RepoParams) => + `${getRepoUrl(...args)}/commits/main`; + +export const fetchLatestBaseRepoCommitSha = async () => { + if (VERCEL_IS_PROVIDER_GITHUB) { + const response = await fetch(getCommitsUrl()); + const data = await response.json(); + return data.sha.slice(0, 7); + } else { + return undefined; + } +}; + +export const isRepoForkedFromBase = async (...args: RepoParams) => { + if (VERCEL_IS_PROVIDER_GITHUB) { + const response = await fetch(getRepoUrl(...args)); + const data = await response.json(); + return data.fork && data.source?.full_name === `${BASE_OWNER}/${BASE_REPO}`; + } else { + return false; + } +};