mirror of
https://github.com/renovatebot/renovate.git
synced 2026-11-02 10:33:39 +00:00
f2896deaaf
* fix(merge-confidence): don't require auth in `platform=local` When dry-running Renovate against a repository to validate it[0], if a repository is using `matchConfidence`, the whole Renovate run is aborted due to missing API credentials. This can be frustrating, and the workaround available is to temporarily remove all package rules use `matchConfidence`, which isn't the best experience. Instead, we should follow the existing pattern to return `null` when loading a Package Rule with `matchConfidence`, as well as DEBUG logging to inform the user why this is happening. [0]: https://www.jvt.me/posts/2026/03/08/renovate-test-config/ * fixup! fix(merge-confidence): don't validate auth in a With debugging from Claude to work out how to get the test to pass. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io> --------- Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io>
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import {
|
|
isArray,
|
|
isNonEmptyString,
|
|
isNullOrUndefined,
|
|
isUndefined,
|
|
} from '@sindresorhus/is';
|
|
import { GlobalConfig } from '../../config/global.ts';
|
|
import type {
|
|
PackageRule,
|
|
PackageRuleInputConfig,
|
|
} from '../../config/types.ts';
|
|
import { MISSING_API_CREDENTIALS } from '../../constants/error-messages.ts';
|
|
import { logger } from '../../logger/index.ts';
|
|
import { getApiToken } from '../merge-confidence/index.ts';
|
|
import { Matcher } from './base.ts';
|
|
|
|
export class MergeConfidenceMatcher extends Matcher {
|
|
override matches(
|
|
{ mergeConfidenceLevel }: PackageRuleInputConfig,
|
|
{ matchConfidence }: PackageRule,
|
|
): boolean | null {
|
|
if (isNullOrUndefined(matchConfidence)) {
|
|
return null;
|
|
}
|
|
|
|
// if we're on `local` platform - for instance to test against a repo - don't error, but don't allow the packageRule either
|
|
if (GlobalConfig.get('platform') === 'local') {
|
|
logger.once.debug(
|
|
"Skipping packageRule(s) with `matchConfidence`, as we're running in platform=local",
|
|
);
|
|
return null;
|
|
}
|
|
|
|
/*
|
|
* Throw an error for unauthenticated use of the matchConfidence matcher.
|
|
*/
|
|
if (isUndefined(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](${GlobalConfig.get('productLinks').documentation}configuration-options/#packagerulesmatchconfidence) and add the required host rule.`;
|
|
throw error;
|
|
}
|
|
|
|
return (
|
|
isArray(matchConfidence) &&
|
|
isNonEmptyString(mergeConfidenceLevel) &&
|
|
matchConfidence.includes(mergeConfidenceLevel)
|
|
);
|
|
}
|
|
}
|