Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(regex): add additional logging for isValidDependency failures #29791

Merged
merged 3 commits into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions lib/modules/manager/custom/regex/strategies.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import is from '@sindresorhus/is';
import { logger } from '../../../../logger';
import { regEx } from '../../../../util/regex';
import type { PackageDependency } from '../../types';
import type { RecursionParameter, RegexManagerConfig } from './types';
Expand All @@ -12,7 +13,7 @@ import {

export function handleAny(
content: string,
_packageFile: string,
packageFile: string,
config: RegexManagerConfig,
): PackageDependency[] {
return config.matchStrings
Expand All @@ -30,12 +31,14 @@ export function handleAny(
),
)
.filter(is.truthy)
.filter(isValidDependency);
.filter((dep: PackageDependency) =>
checkIsValidDependency(dep, packageFile),
);
}

export function handleCombination(
content: string,
_packageFile: string,
packageFile: string,
config: RegexManagerConfig,
): PackageDependency[] {
const matches = config.matchStrings
Expand All @@ -57,7 +60,9 @@ export function handleCombination(
.reduce((base, addition) => mergeExtractionTemplate(base, addition));
return [createDependency(extraction, config)]
.filter(is.truthy)
.filter(isValidDependency);
.filter((dep: PackageDependency) =>
checkIsValidDependency(dep, packageFile),
);
}

export function handleRecursive(
Expand All @@ -78,7 +83,9 @@ export function handleRecursive(
regexes,
})
.filter(is.truthy)
.filter(isValidDependency);
.filter((dep: PackageDependency) =>
checkIsValidDependency(dep, packageFile),
);
}

function processRecursive(parameters: RecursionParameter): PackageDependency[] {
Expand Down Expand Up @@ -109,3 +116,23 @@ function processRecursive(parameters: RecursionParameter): PackageDependency[] {
});
});
}

function checkIsValidDependency(
dep: PackageDependency,
packageFile: string,
): boolean {
const isValid = isValidDependency(dep);
if (!isValid) {
const meta = {
packageDependency: dep,
packageFile,
};
logger.trace(
meta,
'Discovered a package dependency by matching regex, but it did not pass validation. Discarding',
);
return isValid;
}

return isValid;
}
Loading