2022-03-03 09:35:26 +00:00
|
|
|
import { getManagerList } from '../../modules/manager';
|
2021-05-11 10:51:21 +00:00
|
|
|
import type { ValidationMessage } from '../types';
|
|
|
|
import type { CheckManagerArgs } from './types';
|
2019-08-23 13:46:31 +00:00
|
|
|
|
2019-02-20 21:29:38 +00:00
|
|
|
/**
|
|
|
|
* Only if type condition or context condition violated then errors array will be mutated to store metadata
|
|
|
|
*/
|
2019-08-23 13:46:31 +00:00
|
|
|
export function check({
|
|
|
|
resolvedRule,
|
|
|
|
currentPath,
|
|
|
|
}: CheckManagerArgs): ValidationMessage[] {
|
2022-04-20 10:22:23 +00:00
|
|
|
let managersErrMessage: string | undefined;
|
2021-01-29 10:43:42 +00:00
|
|
|
if (Array.isArray(resolvedRule.matchManagers)) {
|
2019-02-20 21:29:38 +00:00
|
|
|
if (
|
2021-01-29 10:43:42 +00:00
|
|
|
resolvedRule.matchManagers.find(
|
2020-04-12 16:09:36 +00:00
|
|
|
(confManager) => !getManagerList().includes(confManager)
|
2019-02-20 21:29:38 +00:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
managersErrMessage = `${currentPath}:
|
2020-08-26 12:59:50 +00:00
|
|
|
You have included an unsupported manager in a package rule. Your list: ${String(
|
2021-01-29 10:43:42 +00:00
|
|
|
resolvedRule.matchManagers
|
2020-08-26 12:59:50 +00:00
|
|
|
)}.
|
2019-02-20 21:29:38 +00:00
|
|
|
Supported managers are: (${getManagerList().join(', ')}).`;
|
|
|
|
}
|
2021-01-29 10:43:42 +00:00
|
|
|
} else if (typeof resolvedRule.matchManagers !== 'undefined') {
|
|
|
|
managersErrMessage = `${currentPath}: Managers should be type of List. You have included ${typeof resolvedRule.matchManagers}.`;
|
2020-03-17 11:15:22 +00:00
|
|
|
}
|
2019-02-20 21:29:38 +00:00
|
|
|
|
|
|
|
return managersErrMessage
|
|
|
|
? [
|
|
|
|
{
|
2021-04-01 13:50:17 +00:00
|
|
|
topic: 'Configuration Error',
|
2019-02-20 21:29:38 +00:00
|
|
|
message: managersErrMessage,
|
|
|
|
},
|
|
|
|
]
|
|
|
|
: [];
|
2019-08-23 13:46:31 +00:00
|
|
|
}
|