From 2feb4cf088c1abed5e43c8df0606df9c68226619 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Thu, 19 Feb 2026 10:27:34 -0600 Subject: [PATCH] Add commit age to admin insights --- src/admin/insights/AdminAppInsightsClient.tsx | 10 +++++++ src/platforms/github.ts | 30 +++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/admin/insights/AdminAppInsightsClient.tsx b/src/admin/insights/AdminAppInsightsClient.tsx index 6661674a..c0415fe2 100644 --- a/src/admin/insights/AdminAppInsightsClient.tsx +++ b/src/admin/insights/AdminAppInsightsClient.tsx @@ -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({ {VERCEL_GIT_COMMIT_MESSAGE ?? DEBUG_COMMIT_MESSAGE} + + ( + {formatDistanceToNow( + codeMeta?.commitDate ?? DEBUG_COMMIT_DATE, + { addSuffix: true }, + )} + ) + } /> `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,