Add for status to app configuration
This commit is contained in:
parent
8f7b973323
commit
843c7046b2
@ -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<Awaited<ReturnType<typeof testConnectionsAction>>> & {
|
||||
simplifiedView?: boolean
|
||||
isTestingConnections?: boolean
|
||||
} & {
|
||||
isForkedFromBaseRepo?: boolean
|
||||
}) {
|
||||
const renderLink = (href: string, text: string, external = true) =>
|
||||
<>
|
||||
@ -665,13 +669,18 @@ export default function SiteChecklistClient({
|
||||
|
||||
{commitSha
|
||||
? commitUrl
|
||||
? <Link
|
||||
title={commitMessage}
|
||||
href={commitUrl}
|
||||
target="_blank"
|
||||
>
|
||||
{commitSha}
|
||||
</Link>
|
||||
? <>
|
||||
<Link
|
||||
title={commitMessage}
|
||||
href={commitUrl}
|
||||
target="_blank"
|
||||
>
|
||||
{commitSha}
|
||||
</Link>
|
||||
|
||||
{isForkedFromBaseRepo &&
|
||||
<span className="text-dim">Forked</span>}
|
||||
</>
|
||||
: <span title={commitMessage}>{commitSha}</span>
|
||||
: 'Not Found'}
|
||||
</div>
|
||||
|
||||
@ -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 (
|
||||
<SiteChecklistClient {...{
|
||||
...CONFIG_CHECKLIST_STATUS,
|
||||
...connectionErrors,
|
||||
isForkedFromBaseRepo,
|
||||
simplifiedView,
|
||||
}} />
|
||||
);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
32
src/utility/github.ts
Normal 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;
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user