From 31b826c96082cda41c9ed34e53ffcb2280245234 Mon Sep 17 00:00:00 2001 From: gfwangjie Date: Thu, 21 May 2026 13:24:03 +0800 Subject: [PATCH] chore: format group HTTP mapping changes --- gitnexus/src/cli/group.ts | 10 ++++------ gitnexus/src/core/group/config-parser.ts | 18 ++++++++++++------ gitnexus/src/core/group/http-mapping.ts | 4 +++- .../test/integration/group/group-sync.test.ts | 4 +--- gitnexus/test/unit/group/sync.test.ts | 10 ++-------- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/gitnexus/src/cli/group.ts b/gitnexus/src/cli/group.ts index a59a1ad2c..07a160620 100644 --- a/gitnexus/src/cli/group.ts +++ b/gitnexus/src/cli/group.ts @@ -29,9 +29,8 @@ export function registerGroupCommands(program: Command): void { ) .action(async (groupName: string, groupPath: string, registryName: string) => { const { getGroupDir, getDefaultGitnexusDir } = await import('../core/group/storage.js'); - const { loadGroupConfig, serializeGroupConfig } = await import( - '../core/group/config-parser.js' - ); + const { loadGroupConfig, serializeGroupConfig } = + await import('../core/group/config-parser.js'); const path = await import('node:path'); const fs = await import('node:fs/promises'); const groupDir = getGroupDir(getDefaultGitnexusDir(), groupName); @@ -52,9 +51,8 @@ export function registerGroupCommands(program: Command): void { .description('Remove a repo from a group') .action(async (groupName: string, repoPath: string) => { const { getGroupDir, getDefaultGitnexusDir } = await import('../core/group/storage.js'); - const { loadGroupConfig, serializeGroupConfig } = await import( - '../core/group/config-parser.js' - ); + const { loadGroupConfig, serializeGroupConfig } = + await import('../core/group/config-parser.js'); const path = await import('node:path'); const fs = await import('node:fs/promises'); const groupDir = getGroupDir(getDefaultGitnexusDir(), groupName); diff --git a/gitnexus/src/core/group/config-parser.ts b/gitnexus/src/core/group/config-parser.ts index 8bda54061..d9f25735a 100644 --- a/gitnexus/src/core/group/config-parser.ts +++ b/gitnexus/src/core/group/config-parser.ts @@ -136,9 +136,7 @@ export function parseGroupConfig(yamlContent: string): GroupConfig { } const target = mapping.to as Record; if (!target.repo || !repoPaths.has(target.repo as string)) { - throw new Error( - `http_mappings[${i}].to.repo "${target.repo}" does not match any repo path`, - ); + throw new Error(`http_mappings[${i}].to.repo "${target.repo}" does not match any repo path`); } if (mapping.match === undefined || String(mapping.match).trim() === '') { throw new Error(`http_mappings[${i}].match is required`); @@ -152,7 +150,9 @@ export function parseGroupConfig(yamlContent: string): GroupConfig { if (!Array.isArray(mapping.methods)) { throw new Error(`http_mappings[${i}].methods must be an array when provided`); } - methods = mapping.methods.map((method) => String(method).trim().toUpperCase()).filter(Boolean); + methods = mapping.methods + .map((method) => String(method).trim().toUpperCase()) + .filter(Boolean); if (methods.length === 0) { throw new Error(`http_mappings[${i}].methods must not be empty`); } @@ -160,7 +160,11 @@ export function parseGroupConfig(yamlContent: string): GroupConfig { let when: Record | undefined; if (mapping.when !== undefined) { - if (typeof mapping.when !== 'object' || Array.isArray(mapping.when) || mapping.when === null) { + if ( + typeof mapping.when !== 'object' || + Array.isArray(mapping.when) || + mapping.when === null + ) { throw new Error(`http_mappings[${i}].when must be an object when provided`); } when = Object.fromEntries( @@ -176,7 +180,9 @@ export function parseGroupConfig(yamlContent: string): GroupConfig { to: { repo: target.repo as string, service: - target.service === undefined || target.service === null ? undefined : String(target.service), + target.service === undefined || target.service === null + ? undefined + : String(target.service), }, methods, match: String(mapping.match), diff --git a/gitnexus/src/core/group/http-mapping.ts b/gitnexus/src/core/group/http-mapping.ts index 3d789f790..d41234426 100644 --- a/gitnexus/src/core/group/http-mapping.ts +++ b/gitnexus/src/core/group/http-mapping.ts @@ -74,7 +74,9 @@ export function applyHttpMappings( } const compiledRules = compileRules(rules); - const providers = contracts.filter((contract) => contract.role === 'provider' && contract.type === 'http'); + const providers = contracts.filter( + (contract) => contract.role === 'provider' && contract.type === 'http', + ); const providerIndex = new Map(); for (const provider of providers) { const key = providerIndexKey(provider.contractId); diff --git a/gitnexus/test/integration/group/group-sync.test.ts b/gitnexus/test/integration/group/group-sync.test.ts index 345a2b069..61f0b2abc 100644 --- a/gitnexus/test/integration/group/group-sync.test.ts +++ b/gitnexus/test/integration/group/group-sync.test.ts @@ -131,8 +131,6 @@ http_mappings: expect(result.crossLinks).toHaveLength(1); expect(result.crossLinks[0].matchType).toBe('manifest'); expect(result.crossLinks[0].contractId).toBe('http::POST::/orders/create'); - expect(result.crossLinks[0].fromContractId).toBe( - 'http::POST::/api/titans/order/1.0.0/create', - ); + expect(result.crossLinks[0].fromContractId).toBe('http::POST::/api/titans/order/1.0.0/create'); }); }); diff --git a/gitnexus/test/unit/group/sync.test.ts b/gitnexus/test/unit/group/sync.test.ts index 0af87c519..15db33148 100644 --- a/gitnexus/test/unit/group/sync.test.ts +++ b/gitnexus/test/unit/group/sync.test.ts @@ -138,11 +138,7 @@ describe('syncGroup', () => { const mockContracts: StoredContract[] = [ { - ...makeContract( - 'http::POST::/api/titans/order/1.0.0/create', - 'consumer', - 'frontend', - ), + ...makeContract('http::POST::/api/titans/order/1.0.0/create', 'consumer', 'frontend'), meta: { method: 'POST', path: '/api/titans/order/1.0.0/create' }, }, { @@ -160,9 +156,7 @@ describe('syncGroup', () => { expect(result.crossLinks).toHaveLength(1); expect(result.crossLinks[0].matchType).toBe('manifest'); expect(result.crossLinks[0].contractId).toBe('http::POST::/orders/create'); - expect(result.crossLinks[0].fromContractId).toBe( - 'http::POST::/api/titans/order/1.0.0/create', - ); + expect(result.crossLinks[0].fromContractId).toBe('http::POST::/api/titans/order/1.0.0/create'); expect(result.crossLinks[0].toContractId).toBe('http::POST::/orders/create'); expect(result.crossLinks[0].to.service).toBe('services/order'); expect(result.unmatched).toHaveLength(0);