mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-09-24 00:51:53 +00:00
Some checks are pending
CI / quality (push) Waiting to run
CI / tests (push) Waiting to run
CI / e2e (push) Waiting to run
CI / Save PR Metadata (push) Blocked by required conditions
CI / CI Gate (push) Blocked by required conditions
Release Candidate / Check if release candidate should run (push) Waiting to run
Release Candidate / ci (push) Blocked by required conditions
Release Candidate / Publish release candidate to npm (push) Blocked by required conditions
37 lines
1,010 B
TypeScript
37 lines
1,010 B
TypeScript
/**
|
|
* Server Mapping Configuration
|
|
*
|
|
* Reads ~/.gitnexus/server-mapping.json to map repo names to service names.
|
|
* Used in embedding text to enrich metadata with microservice context.
|
|
*/
|
|
|
|
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
import os from 'os';
|
|
|
|
const MAPPING_FILE = path.join(os.homedir(), '.gitnexus', 'server-mapping.json');
|
|
|
|
let cachedMapping: Record<string, string> | null = null;
|
|
|
|
/**
|
|
* Read the server mapping file and return the serverName for a given repoName.
|
|
* Returns undefined if no mapping exists.
|
|
*/
|
|
export const readServerMapping = async (repoName: string): Promise<string | undefined> => {
|
|
try {
|
|
if (!cachedMapping) {
|
|
const raw = await fs.readFile(MAPPING_FILE, 'utf-8');
|
|
cachedMapping = JSON.parse(raw);
|
|
}
|
|
return cachedMapping[repoName];
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* Clear the cached mapping (useful for testing or after file changes)
|
|
*/
|
|
export const clearServerMappingCache = (): void => {
|
|
cachedMapping = null;
|
|
};
|