Stop caching GitHub status requests
This commit is contained in:
parent
f246460130
commit
74baa3d8f4
@ -10,7 +10,7 @@ export default function GitHubForkStatusBadgeClient({
|
|||||||
tooltip,
|
tooltip,
|
||||||
}: {
|
}: {
|
||||||
label?: ReactNode
|
label?: ReactNode
|
||||||
style?: 'success' | 'warning' | 'mono'
|
style?: 'success' | 'warning' | 'error' | 'mono'
|
||||||
tooltip?: ReactNode
|
tooltip?: ReactNode
|
||||||
}) {
|
}) {
|
||||||
const classNameForStyle = () => {
|
const classNameForStyle = () => {
|
||||||
@ -22,11 +22,17 @@ export default function GitHubForkStatusBadgeClient({
|
|||||||
'border-green-300/40 dark:border-green-900/50',
|
'border-green-300/40 dark:border-green-900/50',
|
||||||
);
|
);
|
||||||
case 'warning': return clsx(
|
case 'warning': return clsx(
|
||||||
'text-amber-800/90 hover:text-amber-700',
|
'text-amber-800/90 hover:text-amber-800/90',
|
||||||
'dark:text-amber-400 dark:hover:text-amber-400',
|
'dark:text-amber-400 dark:hover:text-amber-400',
|
||||||
'bg-amber-100/40 dark:bg-amber-900/25',
|
'bg-amber-100/40 dark:bg-amber-900/25',
|
||||||
'border-amber-300/40 dark:border-amber-900/50',
|
'border-amber-300/40 dark:border-amber-900/50',
|
||||||
);
|
);
|
||||||
|
case 'error': return clsx(
|
||||||
|
'text-red-700/90 hover:text-red-700/90',
|
||||||
|
'dark:text-red-400 dark:hover:text-red-400',
|
||||||
|
'bg-red-100/20 dark:bg-red-900/25',
|
||||||
|
'border-red-300/40 dark:border-red-900/50',
|
||||||
|
);
|
||||||
default: return clsx(
|
default: return clsx(
|
||||||
'text-main',
|
'text-main',
|
||||||
'bg-white dark:bg-transparent',
|
'bg-white dark:bg-transparent',
|
||||||
|
|||||||
@ -20,28 +20,43 @@ export default async function GitHubForkStatusBadgeServer() {
|
|||||||
isBehind,
|
isBehind,
|
||||||
label,
|
label,
|
||||||
description,
|
description,
|
||||||
|
didError,
|
||||||
} = await getGitHubMetaWithFallback({ owner, repo, branch, commit });
|
} = await getGitHubMetaWithFallback({ owner, repo, branch, commit });
|
||||||
|
|
||||||
|
const repoLink = (text: string) =>
|
||||||
|
<a
|
||||||
|
href={getGitHubRepoUrl({ owner, repo })}
|
||||||
|
target="_blank"
|
||||||
|
className="underline hover:no-underline hover:text-main"
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</a>;
|
||||||
|
|
||||||
|
const isBehindContent = <>
|
||||||
|
{' '}
|
||||||
|
{repoLink('Sync on GitHub')} for latest updates.
|
||||||
|
</>;
|
||||||
|
|
||||||
|
const didErrorContent = <>
|
||||||
|
{' '}
|
||||||
|
Could not connect to {repoLink('GitHub')}.
|
||||||
|
</>;
|
||||||
|
|
||||||
return isForkedFromBase || isBaseRepo
|
return isForkedFromBase || isBaseRepo
|
||||||
? <GitHubForkStatusBadgeClient {...{
|
? <GitHubForkStatusBadgeClient {...{
|
||||||
url,
|
url,
|
||||||
label,
|
label,
|
||||||
tooltip: <>
|
tooltip: <>
|
||||||
{description}
|
{description}
|
||||||
{isBehind && <>
|
{didError
|
||||||
{' '}
|
? didErrorContent
|
||||||
<a
|
: isBehind
|
||||||
href={getGitHubRepoUrl({ owner, repo })}
|
? isBehindContent
|
||||||
target="_blank"
|
: null}
|
||||||
className="underline hover:no-underline hover:text-main"
|
|
||||||
>
|
|
||||||
Sync on GitHub
|
|
||||||
</a>
|
|
||||||
{' '}
|
|
||||||
for latest updates.
|
|
||||||
</>}
|
|
||||||
</>,
|
</>,
|
||||||
style: isBehind === undefined || isBehind ? 'warning' : 'mono',
|
style: didError || isBehind === undefined || isBehind
|
||||||
|
? 'warning'
|
||||||
|
: 'mono',
|
||||||
}} />
|
}} />
|
||||||
: null;
|
: null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,14 +5,13 @@ import {
|
|||||||
} from '@/site/config';
|
} from '@/site/config';
|
||||||
|
|
||||||
const DEFAULT_BRANCH = 'main';
|
const DEFAULT_BRANCH = 'main';
|
||||||
|
|
||||||
const FALLBACK_TEXT = 'Unknown';
|
const FALLBACK_TEXT = 'Unknown';
|
||||||
|
const CACHE_GITHUB_REQUESTS = false;
|
||||||
|
|
||||||
// Cache all results for 2 minutes to avoid rate limiting
|
// Cache all results for 2 minutes to avoid rate limiting
|
||||||
// GitHub API requests limited to 60 requests per hour
|
// GitHub API requests limited to 60 requests per hour
|
||||||
const FETCH_CONFIG: RequestInit = {
|
const FETCH_CONFIG: RequestInit = CACHE_GITHUB_REQUESTS
|
||||||
next: { revalidate: 120 },
|
? { next: { revalidate: 120 } } : {};
|
||||||
};
|
|
||||||
|
|
||||||
interface RepoParams {
|
interface RepoParams {
|
||||||
owner?: string
|
owner?: string
|
||||||
@ -152,6 +151,7 @@ const getGitHubMeta = async (params: RepoParams) => {
|
|||||||
isBehind,
|
isBehind,
|
||||||
label,
|
label,
|
||||||
description,
|
description,
|
||||||
|
didError: false,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -166,6 +166,7 @@ export const getGitHubMetaWithFallback = (params: RepoParams) =>
|
|||||||
behindBy: undefined,
|
behindBy: undefined,
|
||||||
isBehind: undefined,
|
isBehind: undefined,
|
||||||
label: FALLBACK_TEXT,
|
label: FALLBACK_TEXT,
|
||||||
description: FALLBACK_TEXT,
|
description: 'Could not connect to GitHub.',
|
||||||
|
didError: true,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user