fix: 统一 GitHub 仓库凭据匹配大小写
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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<string, unknown> } | 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),
|
||||
|
||||
Reference in New Issue
Block a user