0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/util/package-rules/merge-confidence.ts
2023-11-07 15:50:29 +00:00

35 lines
1.3 KiB
TypeScript

import is from '@sindresorhus/is';
import type { PackageRule, PackageRuleInputConfig } from '../../config/types';
import { MISSING_API_CREDENTIALS } from '../../constants/error-messages';
import { getApiToken } from '../merge-confidence';
import { Matcher } from './base';
export class MergeConfidenceMatcher extends Matcher {
override matches(
{ mergeConfidenceLevel }: PackageRuleInputConfig,
{ matchConfidence }: PackageRule,
): boolean | null {
if (is.nullOrUndefined(matchConfidence)) {
return null;
}
/*
* Throw an error for unauthenticated use of the matchConfidence matcher.
*/
if (is.undefined(getApiToken())) {
const error = new Error(MISSING_API_CREDENTIALS);
error.validationSource = 'MatchConfidence Authenticator';
error.validationError = 'Missing credentials';
error.validationMessage =
'The `matchConfidence` matcher in `packageRules` requires authentication. Please refer to the [documentation](https://docs.renovatebot.com/configuration-options/#matchconfidence) and add the required host rule.';
throw error;
}
return (
is.array(matchConfidence) &&
is.nonEmptyString(mergeConfidenceLevel) &&
matchConfidence.includes(mergeConfidenceLevel)
);
}
}