Add for status to app configuration

This commit is contained in:
Sam Becker 2025-01-30 10:02:43 -06:00
parent 8f7b973323
commit 843c7046b2
5 changed files with 68 additions and 23 deletions

View File

@ -94,6 +94,8 @@ export default function SiteChecklistClient({
storageError, storageError,
kvError, kvError,
aiError, aiError,
// Git Meta
isForkedFromBaseRepo,
// Component props // Component props
simplifiedView, simplifiedView,
isTestingConnections, isTestingConnections,
@ -101,6 +103,8 @@ export default function SiteChecklistClient({
Partial<Awaited<ReturnType<typeof testConnectionsAction>>> & { Partial<Awaited<ReturnType<typeof testConnectionsAction>>> & {
simplifiedView?: boolean simplifiedView?: boolean
isTestingConnections?: boolean isTestingConnections?: boolean
} & {
isForkedFromBaseRepo?: boolean
}) { }) {
const renderLink = (href: string, text: string, external = true) => const renderLink = (href: string, text: string, external = true) =>
<> <>
@ -665,13 +669,18 @@ export default function SiteChecklistClient({
&nbsp;&nbsp; &nbsp;&nbsp;
{commitSha {commitSha
? commitUrl ? commitUrl
? <Link ? <>
title={commitMessage} <Link
href={commitUrl} title={commitMessage}
target="_blank" href={commitUrl}
> target="_blank"
{commitSha} >
</Link> {commitSha}
</Link>
&nbsp;
{isForkedFromBaseRepo &&
<span className="text-dim">Forked</span>}
</>
: <span title={commitMessage}>{commitSha}</span> : <span title={commitMessage}>{commitSha}</span>
: 'Not Found'} : 'Not Found'}
</div> </div>

View File

@ -1,6 +1,11 @@
import SiteChecklistClient from './SiteChecklistClient'; 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 { testConnectionsAction } from '@/admin/actions';
import { isRepoForkedFromBase } from '@/utility/github';
export default async function SiteChecklistServer({ export default async function SiteChecklistServer({
simplifiedView, simplifiedView,
@ -8,10 +13,16 @@ export default async function SiteChecklistServer({
simplifiedView?: boolean simplifiedView?: boolean
}) { }) {
const connectionErrors = await testConnectionsAction().catch(() => ({})); const connectionErrors = await testConnectionsAction().catch(() => ({}));
const isForkedFromBaseRepo = await isRepoForkedFromBase(
VERCEL_GIT_REPO_OWNER,
VERCEL_GIT_REPO_SLUG,
);
return ( return (
<SiteChecklistClient {...{ <SiteChecklistClient {...{
...CONFIG_CHECKLIST_STATUS, ...CONFIG_CHECKLIST_STATUS,
...connectionErrors, ...connectionErrors,
isForkedFromBaseRepo,
simplifiedView, simplifiedView,
}} /> }} />
); );

View File

@ -14,20 +14,21 @@ export const SITE_TITLE =
'Photo Blog'; 'Photo Blog';
// SOURCE // SOURCE
const VERCEL_GIT_PROVIDER = export const VERCEL_GIT_PROVIDER =
process.env.NEXT_PUBLIC_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; 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; 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; 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; 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) ? VERCEL_GIT_COMMIT_SHA.slice(0, 7)
: undefined; : 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 // eslint-disable-next-line max-len
? `https://github.com/${VERCEL_GIT_REPO_OWNER}/${VERCEL_GIT_REPO_SLUG}/commit/${VERCEL_GIT_COMMIT_SHA}` ? `https://github.com/${VERCEL_GIT_REPO_OWNER}/${VERCEL_GIT_REPO_SLUG}/commit/${VERCEL_GIT_COMMIT_SHA}`
: undefined; : undefined;

View File

@ -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);
};

32
src/utility/github.ts Normal file
View File

@ -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;
}
};