0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-01-11 05:39:10 +00:00
renovatebot_renovate/lib/util/package-rules/jsonata.ts
Rhys Arkins 32ecb4ccc8
feat(packageRules): matchJsonata (#31826)
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
2024-10-08 11:32:30 +00:00

37 lines
1.1 KiB
TypeScript

import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
import { logger } from '../../logger';
import { getExpression } from '../jsonata';
import { Matcher } from './base';
export class JsonataMatcher extends Matcher {
override async matches(
inputConfig: PackageRuleInputConfig,
{ matchJsonata }: PackageRule,
): Promise<boolean | null> {
if (!matchJsonata) {
return null;
}
for (const expressionStr of matchJsonata) {
const expression = getExpression(expressionStr);
if (expression instanceof Error) {
logger.warn(
{ errorMessage: expression.message },
'Invalid JSONata expression',
);
} else {
try {
const result = await expression.evaluate(inputConfig);
if (result) {
// Only one needs to match, so return early
return true;
}
} catch (err) {
logger.warn({ err }, 'Error evaluating JSONata expression');
}
}
}
// None matched, so return false
return false;
}
}