Skip to content

Commit

Permalink
fix(config/inherited): set hostRules (#33530)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh authored Jan 17, 2025
1 parent 846c867 commit 6964458
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/workers/repository/init/inherited.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mocked, platform } from '../../../../test/util';
import { hostRules, mocked, platform } from '../../../../test/util';
import * as presets_ from '../../../config/presets';
import type { RenovateConfig } from '../../../config/types';
import * as validation from '../../../config/validation';
Expand Down Expand Up @@ -91,6 +91,27 @@ describe('workers/repository/init/inherited', () => {
expect(logger.warn).not.toHaveBeenCalled();
});

it('should set hostRules from inherited config', async () => {
platform.getRawFile.mockResolvedValue(
`{
"hostRules": [
{
"matchHost": "some-host-url",
"token": "some-token"
}
]
}`,
);
const res = await mergeInheritedConfig(config);
expect(hostRules.getAll()).toMatchObject([
{
matchHost: 'some-host-url',
token: 'some-token',
},
]);
expect(res.hostRules).toBeUndefined();
});

it('should resolve presets found in inherited config', async () => {
platform.getRawFile.mockResolvedValue(
'{"onboarding":false,"labels":["test"],"extends":[":automergeAll"]}',
Expand Down
26 changes: 26 additions & 0 deletions lib/workers/repository/init/inherited.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
} from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { platform } from '../../../modules/platform';
import * as hostRules from '../../../util/host-rules';
import * as queue from '../../../util/http/queue';
import * as throttle from '../../../util/http/throttle';
import * as template from '../../../util/template';

export async function mergeInheritedConfig(
Expand Down Expand Up @@ -102,6 +105,7 @@ export async function mergeInheritedConfig(
}

if (is.nullOrUndefined(filteredConfig.extends)) {
setInheritedHostRules(filteredConfig);
return mergeChildConfig(config, filteredConfig);
}

Expand Down Expand Up @@ -137,5 +141,27 @@ export async function mergeInheritedConfig(
);
}

setInheritedHostRules(filteredConfig);
return mergeChildConfig(config, filteredConfig);
}

function setInheritedHostRules(config: RenovateConfig): void {
if (config.hostRules) {
logger.debug('Setting hostRules from config');
for (const rule of config.hostRules) {
try {
hostRules.add(rule);
} catch (err) {
// istanbul ignore next
logger.warn(
{ err, config: rule },
'Error setting hostRule from config',
);
}
}
// host rules can change concurrency
queue.clear();
throttle.clear();
delete config.hostRules;
}
}

0 comments on commit 6964458

Please sign in to comment.