Skip to content

Commit

Permalink
fix: better fork skip logging (#26754)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins authored Jan 19, 2024
1 parent 86fe603 commit d0f43df
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
28 changes: 28 additions & 0 deletions lib/workers/repository/init/apis.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ describe('workers/repository/init/apis', () => {
expect(workerPlatformConfig).toBeTruthy();
});

it('does not throw for forkProcessing=enabled', async () => {
platform.initRepo.mockResolvedValueOnce({
defaultBranch: 'master',
isFork: true,
repoFingerprint: '123',
});
platform.getJsonFile.mockResolvedValueOnce({
forkProcessing: 'enabled',
});
const workerPlatformConfig = await initApis(config);
expect(workerPlatformConfig).toBeTruthy();
});

it('ignores platform.getJsonFile() failures', async () => {
platform.initRepo.mockResolvedValueOnce({
defaultBranch: 'master',
Expand All @@ -91,6 +104,21 @@ describe('workers/repository/init/apis', () => {
).resolves.not.toThrow();
});

it('throws for fork with platform.getJsonFile() failures', async () => {
platform.initRepo.mockResolvedValueOnce({
defaultBranch: 'master',
isFork: true,
repoFingerprint: '123',
});
platform.getJsonFile.mockRejectedValue(new Error());
await expect(
initApis({
...config,
forkProcessing: 'disabled',
}),
).rejects.toThrow(REPOSITORY_FORKED);
});

it('uses the onboardingConfigFileName if set', async () => {
platform.initRepo.mockResolvedValueOnce({
defaultBranch: 'master',
Expand Down
33 changes: 25 additions & 8 deletions lib/workers/repository/init/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type WorkerPlatformConfig = RepoResult &
Record<string, any>;

// TODO #22198
const defaultConfigFile = (config: RenovateConfig): string =>
const getDefaultConfigFile = (config: RenovateConfig): string =>
configFileNames.includes(config.onboardingConfigFileName!)
? config.onboardingConfigFileName!
: configFileNames[0];
Expand All @@ -30,7 +30,7 @@ async function validateOptimizeForDisabled(
config: RenovateConfig,
): Promise<void> {
if (config.optimizeForDisabled) {
const renovateConfig = await getJsonFile(defaultConfigFile(config));
const renovateConfig = await getJsonFile(getDefaultConfigFile(config));
if (renovateConfig?.enabled === false) {
throw new Error(REPOSITORY_DISABLED_BY_CONFIG);
}
Expand Down Expand Up @@ -62,14 +62,31 @@ async function validateOptimizeForDisabled(

async function validateIncludeForks(config: RenovateConfig): Promise<void> {
if (config.forkProcessing !== 'enabled' && config.isFork) {
const renovateConfig = await getJsonFile(defaultConfigFile(config));
if (
renovateConfig?.includeForks !== true &&
renovateConfig?.forkProcessing !== 'enabled'
) {
const defaultConfigFile = getDefaultConfigFile(config);
const repoConfig = await getJsonFile(defaultConfigFile);
if (!repoConfig) {
logger.debug(
`Default config file ${defaultConfigFile} not found in repo`,
);
throw new Error(REPOSITORY_FORKED);
}
logger.debug('Repository config enables forks - continuing');
if (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);
}
}

Expand Down

0 comments on commit d0f43df

Please sign in to comment.