refactor: customManager mandatory fields check (#28832)

This commit is contained in:
Rhys Arkins 2024-05-04 16:53:31 +02:00 committed by GitHub
parent 5f1286ff00
commit c3b9ef81e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -806,6 +806,19 @@ export async function validateConfig(
return { errors, warnings };
}
function hasField(
customManager: Partial<RegexManagerConfig>,
field: string,
): boolean {
const templateField = `${field}Template` as keyof RegexManagerTemplates;
return !!(
customManager[templateField] ??
customManager.matchStrings?.some((matchString) =>
matchString.includes(`(?<${field}>`),
)
);
}
function validateRegexManagerFields(
customManager: Partial<RegexManagerConfig>,
currentPath: string,
@ -835,13 +848,7 @@ function validateRegexManagerFields(
const mandatoryFields = ['depName', 'currentValue', 'datasource'];
for (const field of mandatoryFields) {
const templateField = `${field}Template` as keyof RegexManagerTemplates;
if (
!customManager[templateField] &&
!customManager.matchStrings?.some((matchString) =>
matchString.includes(`(?<${field}>`),
)
) {
if (!hasField(customManager, field)) {
errors.push({
topic: 'Configuration Error',
message: `Regex Managers must contain ${field}Template configuration or regex group named ${field}`,