Files
renovate/lib/util/package-rules/merge-confidence.ts
Jamie Tanna f2896deaaf fix(merge-confidence): don't require auth in platform=local (#45769)
* 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>
2026-09-09 13:54:13 +00:00

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)
);
}
}