-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
merge-confidence.ts
34 lines (31 loc) · 1.25 KB
/
merge-confidence.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)
);
}
}