From 8061fd2f71933055ea2dce4104a7ad4db76b30ea Mon Sep 17 00:00:00 2001 From: Codex Date: Tue, 14 Jul 2026 03:08:47 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BB=9F=E4=B8=80=20GitHub=20=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=87=AD=E6=8D=AE=E5=8C=B9=E9=85=8D=E5=A4=A7=E5=B0=8F?= =?UTF-8?q?=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/src/gh-token-repository-override.test.ts | 16 ++++++++++++++++ scripts/src/gh/auth-and-safety.ts | 14 +++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/scripts/src/gh-token-repository-override.test.ts b/scripts/src/gh-token-repository-override.test.ts index 541b7b04..e1e3fff9 100644 --- a/scripts/src/gh-token-repository-override.test.ts +++ b/scripts/src/gh-token-repository-override.test.ts @@ -84,6 +84,22 @@ describe("GitHub repository token overrides", () => { expect(selected.probe).toMatchObject({ source: "yaml-token-source", scope: "repository-override", yamlSourcePriority: "before-env" }); }); + test("matches repository overrides without case sensitivity", () => { + delete process.env.GH_TOKEN; + delete process.env.GITHUB_TOKEN; + const authConfig = testAuthConfig(); + + for (const repo of ["PikaInc/selfmedia", "pikainc/SELFMEDIA", "PIKAINC/SELFMEDIA"]) { + const selected = resolveToken(repo, false, authConfig); + expect(selected.token).toBe("selfmedia-token"); + expect(selected.probe).toMatchObject({ scope: "repository-override", sourceRef: "selfmedia-token.txt", valuesPrinted: false }); + } + + const global = resolveToken("PikasTech/UniDesk", false, authConfig); + expect(global.token).toBe("global-token"); + expect(global.probe).toMatchObject({ scope: "global", sourceRef: "global-token.txt", valuesPrinted: false }); + }); + test("uses the final positional repository for issue and PR token selection", () => { delete process.env.GH_TOKEN; delete process.env.GITHUB_TOKEN; diff --git a/scripts/src/gh/auth-and-safety.ts b/scripts/src/gh/auth-and-safety.ts index 2082c988..b9542157 100644 --- a/scripts/src/gh/auth-and-safety.ts +++ b/scripts/src/gh/auth-and-safety.ts @@ -31,6 +31,10 @@ export interface GitHubYamlAuthConfig { repositoryOverrides: GitHubYamlTokenSourceConfig[]; } +function repositoryLookupKey(repository: string): string { + return repository.toLowerCase(); +} + export function readIssueLifecycleCommentBody(options: GitHubOptions, command: string): { body: string; bodySource: Record } | null { if (options.comment === undefined && options.commentFile === undefined) return null; if (options.comment !== undefined) { @@ -59,7 +63,10 @@ export function tokenFromEnvironment(): GitHubTokenProbe { } export function tokenFromYamlSource(repo: string, authConfig: GitHubYamlAuthConfig = readGitHubYamlAuthConfig()): { token: string | null; probe: GitHubTokenProbe } { - const override = authConfig.repositoryOverrides.find((candidate) => candidate.repository === repo) ?? null; + const repoLookupKey = repositoryLookupKey(repo); + const override = authConfig.repositoryOverrides.find((candidate) => ( + candidate.repository !== undefined && repositoryLookupKey(candidate.repository) === repoLookupKey + )) ?? null; const config = override ?? authConfig.tokenSource; if (config === null || config.enabled === false) { return { @@ -162,8 +169,9 @@ function readGitHubYamlAuthConfig(): GitHubYamlAuthConfig { const configRef = `${GITHUB_REPOSITORY_OVERRIDES_CONFIG_REF}[${index}]`; const override = asRecord(value, configRef); const repository = repositoryField(override, "repository", configRef); - if (seenRepositories.has(repository)) throw new Error(`${GITHUB_REPOSITORY_OVERRIDES_CONFIG_REF} contains duplicate repository ${repository}`); - seenRepositories.add(repository); + const repositoryKey = repositoryLookupKey(repository); + if (seenRepositories.has(repositoryKey)) throw new Error(`${GITHUB_REPOSITORY_OVERRIDES_CONFIG_REF} contains duplicate repository ${repository}`); + seenRepositories.add(repositoryKey); return { repository, priority: tokenSourcePriorityField(override, "priority", configRef),