Add commit age to admin insights
This commit is contained in:
parent
c3c7d6858a
commit
2feb4cf088
@ -51,9 +51,11 @@ import MaskedScroll from '@/components/MaskedScroll';
|
|||||||
import IconNext from '@/components/icons/IconNext';
|
import IconNext from '@/components/icons/IconNext';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import IconNode from '@/components/icons/IconNode';
|
import IconNode from '@/components/icons/IconNode';
|
||||||
|
import { formatDistanceToNow } from 'date-fns';
|
||||||
|
|
||||||
const DEBUG_COMMIT_SHA = '4cd29ed';
|
const DEBUG_COMMIT_SHA = '4cd29ed';
|
||||||
const DEBUG_COMMIT_MESSAGE = 'Long commit message for debugging purposes';
|
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_BEHIND_BY = 9;
|
||||||
const DEBUG_PHOTOS_NEED_SYNC_COUNT = 7;
|
const DEBUG_PHOTOS_NEED_SYNC_COUNT = 7;
|
||||||
|
|
||||||
@ -283,6 +285,14 @@ export default function AdminAppInsightsClient({
|
|||||||
<span className="truncate">
|
<span className="truncate">
|
||||||
{VERCEL_GIT_COMMIT_MESSAGE ?? DEBUG_COMMIT_MESSAGE}
|
{VERCEL_GIT_COMMIT_MESSAGE ?? DEBUG_COMMIT_MESSAGE}
|
||||||
</span>
|
</span>
|
||||||
|
<span className="text-dim">
|
||||||
|
(<span className="truncate">
|
||||||
|
{formatDistanceToNow(
|
||||||
|
codeMeta?.commitDate ?? DEBUG_COMMIT_DATE,
|
||||||
|
{ addSuffix: true },
|
||||||
|
)}
|
||||||
|
</span>)
|
||||||
|
</span>
|
||||||
</a>}
|
</a>}
|
||||||
/>
|
/>
|
||||||
<ScoreCardRow
|
<ScoreCardRow
|
||||||
|
|||||||
@ -14,6 +14,15 @@ interface RepoParams {
|
|||||||
commit?: string
|
commit?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface CommitDetails {
|
||||||
|
commit: {
|
||||||
|
committer: {
|
||||||
|
date: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stats: { total: number, additions: number, deletions: number },
|
||||||
|
}
|
||||||
|
|
||||||
const fetchGitHub = async (
|
const fetchGitHub = async (
|
||||||
url: string,
|
url: string,
|
||||||
cacheRequest = true,
|
cacheRequest = true,
|
||||||
@ -76,6 +85,9 @@ const getGitHubApiRepoUrl = ({
|
|||||||
}: RepoParams = {}) =>
|
}: RepoParams = {}) =>
|
||||||
`https://api.github.com/repos/${owner}/${repo}`;
|
`https://api.github.com/repos/${owner}/${repo}`;
|
||||||
|
|
||||||
|
const getGitHubApiCommitUrl = (params?: RepoParams) =>
|
||||||
|
`${getGitHubApiRepoUrl(params)}/commits/${params?.commit}`;
|
||||||
|
|
||||||
const getGitHubApiCommitsUrl = (params?: RepoParams) =>
|
const getGitHubApiCommitsUrl = (params?: RepoParams) =>
|
||||||
`${getGitHubApiRepoUrl(params)}/commits/${params?.branch || DEFAULT_BRANCH}`;
|
`${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 getGitHubCommitsBehindFromRepo = async (params?: RepoParams) => {
|
||||||
const data = await fetchGitHub(getGitHubApiCompareToRepoUrl(params));
|
const data = await fetchGitHub(getGitHubApiCompareToRepoUrl(params));
|
||||||
return data.behind_by as number;
|
return data.behind_by as number;
|
||||||
@ -139,6 +161,7 @@ export const getGitHubMeta = async (params: RepoParams) => {
|
|||||||
|
|
||||||
const isBaseRepo = isRepoBaseRepo(params);
|
const isBaseRepo = isRepoBaseRepo(params);
|
||||||
|
|
||||||
|
let commitDate: Date | undefined;
|
||||||
let isForkedFromBase: boolean | undefined;
|
let isForkedFromBase: boolean | undefined;
|
||||||
let isBehind: boolean | undefined;
|
let isBehind: boolean | undefined;
|
||||||
let behindBy: number | undefined;
|
let behindBy: number | undefined;
|
||||||
@ -146,14 +169,16 @@ export const getGitHubMeta = async (params: RepoParams) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const results = await Promise.all([
|
const results = await Promise.all([
|
||||||
|
getCommitDetails(params),
|
||||||
getIsRepoForkedFromBase(params),
|
getIsRepoForkedFromBase(params),
|
||||||
isBaseRepo && params.commit
|
isBaseRepo && params.commit
|
||||||
? getGitHubCommitsBehindFromCommit(params)
|
? getGitHubCommitsBehindFromCommit(params)
|
||||||
: getGitHubCommitsBehindFromRepo(params),
|
: getGitHubCommitsBehindFromRepo(params),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
isForkedFromBase = results[0];
|
commitDate = results[0]?.date;
|
||||||
behindBy = results[1];
|
isForkedFromBase = results[1];
|
||||||
|
behindBy = results[2];
|
||||||
|
|
||||||
isBehind = behindBy === undefined
|
isBehind = behindBy === undefined
|
||||||
? undefined
|
? undefined
|
||||||
@ -169,6 +194,7 @@ export const getGitHubMeta = async (params: RepoParams) => {
|
|||||||
urlRepo,
|
urlRepo,
|
||||||
urlBranch,
|
urlBranch,
|
||||||
urlCommit,
|
urlCommit,
|
||||||
|
commitDate,
|
||||||
isForkedFromBase,
|
isForkedFromBase,
|
||||||
isBaseRepo,
|
isBaseRepo,
|
||||||
behindBy,
|
behindBy,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user