diff --git a/lib/modules/platform/index.spec.ts b/lib/modules/platform/index.spec.ts index 660e33344dd79799690f2ada2e766bcf849999aa..0c9df4dd743cc3f9ea5f8ddac9d12d338f7a9100 100644 --- a/lib/modules/platform/index.spec.ts +++ b/lib/modules/platform/index.spec.ts @@ -119,34 +119,81 @@ describe('modules/platform/index', () => { }); }); - it('merges platform hostRules with additionalHostRules', async () => { - const config = { - platform: 'github' as PlatformId, - endpoint: 'https://api.github.com', - gitAuthor: 'user@domain.com', - username: 'abc', - token: '123', - }; + describe('when platform endpoint is https://api.github.com/', () => { + it('merges config hostRules with platform hostRules', async () => { + const config = { + platform: 'github' as PlatformId, + endpoint: 'https://api.github.com', + gitAuthor: 'user@domain.com', + username: 'abc', + token: '123', + hostRules: [ + { + hostType: 'github', + matchHost: 'github.com', + token: '456', + username: 'def', + }, + ], + }; - expect(await platform.initPlatform(config)).toEqual({ - endpoint: 'https://api.github.com/', - gitAuthor: 'user@domain.com', - hostRules: [ - { - hostType: 'docker', - matchHost: 'ghcr.io', - password: '123', - username: 'USERNAME', - }, - { - hostType: 'github', - matchHost: 'api.github.com', - token: '123', - username: 'abc', - }, - ], - platform: 'github', - renovateUsername: 'abc', + expect(await platform.initPlatform(config)).toEqual({ + endpoint: 'https://api.github.com/', + gitAuthor: 'user@domain.com', + hostRules: [ + { + hostType: 'github', + matchHost: 'github.com', + token: '456', + username: 'def', + }, + { + hostType: 'docker', + matchHost: 'ghcr.io', + password: '123', + username: 'USERNAME', + }, + { + hostType: 'github', + matchHost: 'api.github.com', + token: '123', + username: 'abc', + }, + ], + platform: 'github', + renovateUsername: 'abc', + }); + }); + + it('merges platform hostRules with additionalHostRules', async () => { + const config = { + platform: 'github' as PlatformId, + endpoint: 'https://api.github.com', + gitAuthor: 'user@domain.com', + username: 'abc', + token: '123', + }; + + expect(await platform.initPlatform(config)).toEqual({ + endpoint: 'https://api.github.com/', + gitAuthor: 'user@domain.com', + hostRules: [ + { + hostType: 'docker', + matchHost: 'ghcr.io', + password: '123', + username: 'USERNAME', + }, + { + hostType: 'github', + matchHost: 'api.github.com', + token: '123', + username: 'abc', + }, + ], + platform: 'github', + renovateUsername: 'abc', + }); }); }); }); diff --git a/lib/modules/platform/index.ts b/lib/modules/platform/index.ts index 7b2a3f20cf08bec2206fbfe021ed9069d26ea8f4..7c9b4bc4dfc60949bc610115ca372d60ad24d8cb 100644 --- a/lib/modules/platform/index.ts +++ b/lib/modules/platform/index.ts @@ -47,7 +47,14 @@ export async function initPlatform(config: AllConfig): Promise<AllConfig> { setPlatformApi(config.platform!); // TODO: types const platformInfo = await platform.initPlatform(config); - const returnConfig: any = { ...config, ...platformInfo }; + const returnConfig: any = { + ...config, + ...platformInfo, + hostRules: [ + ...(config.hostRules ?? []), + ...(platformInfo?.hostRules ?? []), + ], + }; // istanbul ignore else if (config?.gitAuthor) { logger.debug(`Using configured gitAuthor (${config.gitAuthor})`); @@ -75,7 +82,6 @@ export async function initPlatform(config: AllConfig): Promise<AllConfig> { delete returnConfig[field]; } }); - returnConfig.hostRules = returnConfig.hostRules || []; const typedPlatformRule = { ...platformRule, hostType: returnConfig.platform,