Skip to content

Commit

Permalink
feat: check for dot platform org preset when onboarding
Browse files Browse the repository at this point in the history
Checks for a renovate.json file in a repo like org/.github and uses it during onboarding if found.

Closes #7422
  • Loading branch information
rarkins committed Oct 7, 2020
1 parent 46cc3c5 commit 82cdf26
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/workers/repository/onboarding/branch/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,43 @@ describe('workers/repository/onboarding/branch', () => {
beforeEach(() => {
jest.clearAllMocks();
config = getConfig();
config.platform = 'github';
config.repository = 'some/repo';
});
describe('getOnboardingConfig', () => {
it('handles finding an organization preset', async () => {
mockedPresets.getPreset.mockResolvedValueOnce({ enabled: true });
onboardingConfig = await getOnboardingConfig(config);
expect(mockedPresets.getPreset).toHaveBeenCalledTimes(1);
expect(JSON.parse(onboardingConfig).extends[0]).toEqual(
'local>some/renovate-config'
);
});
it('handles finding an organization dot platform preset', async () => {
mockedPresets.getPreset.mockRejectedValueOnce(
new Error(PRESET_DEP_NOT_FOUND)
);
mockedPresets.getPreset.mockResolvedValueOnce({ enabled: true });
onboardingConfig = await getOnboardingConfig(config);
expect(mockedPresets.getPreset).toHaveBeenCalledTimes(2);
expect(JSON.parse(onboardingConfig).extends[0]).toEqual(
'local>some/.github:renovate'
);
});
it('handles not finding an organization preset', async () => {
mockedPresets.getPreset.mockRejectedValue(
new Error(PRESET_DEP_NOT_FOUND)
);
onboardingConfig = await getOnboardingConfig(config);
expect(mockedPresets.getPreset).toHaveBeenCalledTimes(1);
expect(mockedPresets.getPreset).toHaveBeenCalledTimes(2);
expect(JSON.parse(onboardingConfig)).toEqual(config.onboardingConfig);
});
it('ignores an unknown error', async () => {
mockedPresets.getPreset.mockRejectedValue(
new Error('unknown error for test')
);
onboardingConfig = await getOnboardingConfig(config);
expect(mockedPresets.getPreset).toHaveBeenCalledTimes(1);
expect(mockedPresets.getPreset).toHaveBeenCalledTimes(2);
expect(JSON.parse(onboardingConfig)).toEqual(config.onboardingConfig);
});
});
Expand Down
13 changes: 13 additions & 0 deletions lib/workers/repository/onboarding/branch/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ export async function getOnboardingConfig(
}
}

if (!orgPreset) {
// Check for org/.{{platform}}
try {
const orgDotPlatformConfig = `local>${orgName}/.${config.platform}:renovate`;
await getPreset(orgDotPlatformConfig, config);
orgPreset = orgDotPlatformConfig;
} catch (err) {
if (err.message !== PRESET_DEP_NOT_FOUND) {
logger.warn({ err }, 'Unknown error fetching default owner preset');
}
}
}

if (orgPreset) {
onboardingConfig = {
$schema: 'https://docs.renovatebot.com/renovate-schema.json',
Expand Down

0 comments on commit 82cdf26

Please sign in to comment.