mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 15:01:49 +00:00
914c55b03c
* refactor(terraform-module): extract getRegistryRepository to utils * refactor(terraform-module): add zod schemas and validate service discovery * refactor(terraform-module): use zod schemas in query methods and inline fixtures * fix(terraform): update hash test to use valid service discovery response * refactor(terraform-module): address review feedback * style: biome lint fix * refactor(terraform-module): address review feedback
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { regEx } from '../../../util/regex.ts';
|
|
import { coerceString } from '../../../util/string.ts';
|
|
import { isHttpUrl, joinUrlParts } from '../../../util/url.ts';
|
|
import type {
|
|
ServiceDiscoveryEndpointType,
|
|
ServiceDiscoveryResponse,
|
|
} from './schema.ts';
|
|
import type { RegistryRepository } from './types.ts';
|
|
|
|
export function createSDBackendURL(
|
|
registryURL: string,
|
|
sdType: ServiceDiscoveryEndpointType,
|
|
sdResult: ServiceDiscoveryResponse,
|
|
subPath: string,
|
|
): string {
|
|
const sdEndpoint = sdResult[sdType] ?? '';
|
|
const fullPath = joinUrlParts(sdEndpoint, subPath);
|
|
if (isHttpUrl(fullPath)) {
|
|
return fullPath;
|
|
}
|
|
return joinUrlParts(registryURL, fullPath);
|
|
}
|
|
|
|
export function getRegistryRepository(
|
|
packageName: string,
|
|
registryUrl: string | undefined,
|
|
): RegistryRepository {
|
|
let registry: string;
|
|
const split = packageName.split('/');
|
|
if (split.length > 3 && split[0].includes('.')) {
|
|
registry = split.shift()!;
|
|
} else {
|
|
registry = coerceString(registryUrl);
|
|
}
|
|
if (!regEx(/^https?:\/\//).test(registry)) {
|
|
registry = `https://${registry}`;
|
|
}
|
|
const repository = split.join('/');
|
|
return {
|
|
registry,
|
|
repository,
|
|
};
|
|
}
|