Add commit age to admin insights

This commit is contained in:
Sam Becker 2026-02-19 10:27:34 -06:00
parent c3c7d6858a
commit 2feb4cf088
2 changed files with 38 additions and 2 deletions

View File

@ -51,9 +51,11 @@ import MaskedScroll from '@/components/MaskedScroll';
import IconNext from '@/components/icons/IconNext';
import Link from 'next/link';
import IconNode from '@/components/icons/IconNode';
import { formatDistanceToNow } from 'date-fns';
const DEBUG_COMMIT_SHA = '4cd29ed';
const DEBUG_COMMIT_MESSAGE = 'Long commit message for debugging purposes';
const DEBUG_COMMIT_DATE = new Date('2026-02-18T00:00:00Z');
const DEBUG_BEHIND_BY = 9;
const DEBUG_PHOTOS_NEED_SYNC_COUNT = 7;
@ -283,6 +285,14 @@ export default function AdminAppInsightsClient({
<span className="truncate">
{VERCEL_GIT_COMMIT_MESSAGE ?? DEBUG_COMMIT_MESSAGE}
</span>
<span className="text-dim">
(<span className="truncate">
{formatDistanceToNow(
codeMeta?.commitDate ?? DEBUG_COMMIT_DATE,
{ addSuffix: true },
)}
</span>)
</span>
</a>}
/>
<ScoreCardRow

View File

@ -14,6 +14,15 @@ interface RepoParams {
commit?: string
};
interface CommitDetails {
commit: {
committer: {
date: string
}
}
stats: { total: number, additions: number, deletions: number },
}
const fetchGitHub = async (
url: string,
cacheRequest = true,
@ -76,6 +85,9 @@ const getGitHubApiRepoUrl = ({
}: RepoParams = {}) =>
`https://api.github.com/repos/${owner}/${repo}`;
const getGitHubApiCommitUrl = (params?: RepoParams) =>
`${getGitHubApiRepoUrl(params)}/commits/${params?.commit}`;
const getGitHubApiCommitsUrl = (params?: RepoParams) =>
`${getGitHubApiRepoUrl(params)}/commits/${params?.branch || DEFAULT_BRANCH}`;
@ -108,6 +120,16 @@ const getIsRepoForkedFromBase = async (params: RepoParams) => {
);
};
const getCommitDetails = async (params: RepoParams) => {
const data: CommitDetails = await fetchGitHub(getGitHubApiCommitUrl(params));
return data?.commit?.committer?.date && data.stats
? {
date: new Date(data.commit.committer.date),
stats: data.stats,
}
: undefined;
};
const getGitHubCommitsBehindFromRepo = async (params?: RepoParams) => {
const data = await fetchGitHub(getGitHubApiCompareToRepoUrl(params));
return data.behind_by as number;
@ -139,6 +161,7 @@ export const getGitHubMeta = async (params: RepoParams) => {
const isBaseRepo = isRepoBaseRepo(params);
let commitDate: Date | undefined;
let isForkedFromBase: boolean | undefined;
let isBehind: boolean | undefined;
let behindBy: number | undefined;
@ -146,14 +169,16 @@ export const getGitHubMeta = async (params: RepoParams) => {
try {
const results = await Promise.all([
getCommitDetails(params),
getIsRepoForkedFromBase(params),
isBaseRepo && params.commit
? getGitHubCommitsBehindFromCommit(params)
: getGitHubCommitsBehindFromRepo(params),
]);
isForkedFromBase = results[0];
behindBy = results[1];
commitDate = results[0]?.date;
isForkedFromBase = results[1];
behindBy = results[2];
isBehind = behindBy === undefined
? undefined
@ -169,6 +194,7 @@ export const getGitHubMeta = async (params: RepoParams) => {
urlRepo,
urlBranch,
urlCommit,
commitDate,
isForkedFromBase,
isBaseRepo,
behindBy,