fix: read public repositories without scoped App token minting

This commit is contained in:
tdurieux committed 2026-09-14 16:50:18 +02:00
1 parent 8b9f79502b
commit 2d153dd353
5 files changed
+97 -70

No files matched your search

+6 -2
View File
@@ -1,12 +1,16 @@
import { createHash } from "crypto";
interface TokenContext { quotaKey: string; renew: (force?: boolean) => Promise<string>; }
interface TokenContext { quotaKey: string; renew: (force?: boolean) => Promise<string>; publicRepository?: string; }
const contexts = new Map<string, TokenContext>();
export function registerGitHubToken(token: string, context: TokenContext) {
if (contexts.size >= 2000 && !contexts.has(token)) contexts.delete(contexts.keys().next().value!);
contexts.set(token, context);
}
export function githubTokenContext(token: string) { return contexts.get(token); }
export function githubTokenContext(token: string) {
const context = contexts.get(token);
if (!context && token.startsWith("public-read:")) throw new Error("Public repository access context expired");
return context;
}
export function githubQuotaKey(token: string) {
return contexts.get(token)?.quotaKey || createHash("sha256").update(token).digest("hex").slice(0, 24);
}