mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-31 01:37:24 +00:00
b62fe59594
We dropped the "bot" from our terminology long ago, but it looks like we've got some outdated docs + code that reference it. We should remove this to keep things consistent. A `fix`, as we're changing the commit author's name, and log lines. Co-authored-by: Claude Sonnet 5 <jamie.tanna+claude-code@mend.io> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
113 lines
3.5 KiB
TypeScript
113 lines
3.5 KiB
TypeScript
import type { RenovateConfig } from '../../../config/types.ts';
|
|
import {
|
|
REPOSITORY_DISABLED_BY_CONFIG,
|
|
REPOSITORY_FORKED,
|
|
} from '../../../constants/error-messages.ts';
|
|
import { logger } from '../../../logger/index.ts';
|
|
import type {
|
|
RepoParams,
|
|
RepoResult,
|
|
} from '../../../modules/platform/index.ts';
|
|
import { platform } from '../../../modules/platform/index.ts';
|
|
import { getDefaultConfigFileName } from '../onboarding/common.ts';
|
|
|
|
// TODO: fix types (#22198)
|
|
export type WorkerPlatformConfig = RepoResult &
|
|
RenovateConfig &
|
|
Record<string, any>;
|
|
|
|
async function getJsonFile(file: string): Promise<RenovateConfig | null> {
|
|
try {
|
|
return await platform.getJsonFile(file);
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
async function validateOptimizeForDisabled(
|
|
config: RenovateConfig,
|
|
): Promise<void> {
|
|
if (config.optimizeForDisabled) {
|
|
const renovateConfig = await getJsonFile(getDefaultConfigFileName());
|
|
if (renovateConfig?.enabled === false) {
|
|
throw new Error(REPOSITORY_DISABLED_BY_CONFIG);
|
|
}
|
|
/*
|
|
* The following is to support a use case within Mend customers where:
|
|
* - Admins configure and install Renovate into every repo
|
|
* - Admins configure `extends: [':disableRenovate'] in order to skip repos by default
|
|
* - Repo users can push a `renovate.json` containing `extends: [':enableRenovate']` to re-enable Renovate
|
|
*/
|
|
if (config.extends?.includes(':disableRenovate')) {
|
|
logger.debug(
|
|
'Global config disables Renovate - checking renovate.json to see if it is re-enabled',
|
|
);
|
|
if (
|
|
renovateConfig?.extends?.includes(':enableRenovate') ??
|
|
renovateConfig?.ignorePresets?.includes(':disableRenovate') ??
|
|
renovateConfig?.enabled
|
|
) {
|
|
logger.debug('Repository config re-enables Renovate - continuing');
|
|
} else {
|
|
logger.debug(
|
|
'Repository config does not re-enable Renovate - skipping',
|
|
);
|
|
throw new Error(REPOSITORY_DISABLED_BY_CONFIG);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
async function validateIncludeForks(config: RenovateConfig): Promise<void> {
|
|
if (config.forkProcessing !== 'enabled' && config.isFork) {
|
|
const defaultConfigFile = getDefaultConfigFileName();
|
|
const repoConfig = await getJsonFile(defaultConfigFile);
|
|
if (!repoConfig) {
|
|
logger.debug(
|
|
`Default config file ${defaultConfigFile} not found in repo`,
|
|
);
|
|
throw new Error(REPOSITORY_FORKED);
|
|
}
|
|
// TODO: global only setting
|
|
if ('includeForks' in repoConfig && repoConfig.includeForks) {
|
|
logger.debug(
|
|
`Found legacy setting includeForks in ${defaultConfigFile} - continuing`,
|
|
);
|
|
return;
|
|
}
|
|
if (repoConfig.forkProcessing === 'enabled') {
|
|
logger.debug(
|
|
`Found forkProcessing=enabled in ${defaultConfigFile} - continuing`,
|
|
);
|
|
return;
|
|
}
|
|
logger.debug(
|
|
{ config: repoConfig },
|
|
`Default config file ${defaultConfigFile} found in repo but does not enable forks`,
|
|
);
|
|
throw new Error(REPOSITORY_FORKED);
|
|
}
|
|
}
|
|
|
|
// TODO: fix types (#22198)
|
|
async function getPlatformConfig(
|
|
config: RepoParams,
|
|
): Promise<WorkerPlatformConfig> {
|
|
const platformConfig = await platform.initRepo(config);
|
|
return {
|
|
...config,
|
|
...platformConfig,
|
|
};
|
|
}
|
|
|
|
// TODO: fix types (#22198)
|
|
export async function initApis(
|
|
input: RenovateConfig,
|
|
): Promise<WorkerPlatformConfig> {
|
|
let config: WorkerPlatformConfig = { ...input } as never;
|
|
config = await getPlatformConfig(config as never);
|
|
await validateOptimizeForDisabled(config);
|
|
await validateIncludeForks(config);
|
|
return config;
|
|
}
|