-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add organization-level presets (#7403)
Co-authored-by: Michael Kriese <[email protected]> Co-authored-by: Rhys Arkins <[email protected]>
- Loading branch information
1 parent
5896d9c
commit 4085275
Showing
9 changed files
with
84 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { RenovateConfig, getConfig } from '../../../../../test/util'; | ||
import * as presets from '../../../../config/presets'; | ||
import { PRESET_DEP_NOT_FOUND } from '../../../../config/presets/util'; | ||
import { getOnboardingConfig } from './config'; | ||
|
||
jest.mock('../../../../config/presets'); | ||
|
||
const mockedPresets = presets as jest.Mocked<typeof presets>; | ||
|
||
describe('workers/repository/onboarding/branch', () => { | ||
let config: RenovateConfig; | ||
let onboardingConfig: string; | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
config = getConfig(); | ||
config.repository = 'some/repo'; | ||
}); | ||
describe('getOnboardingConfig', () => { | ||
it('handles finding an organization preset', async () => { | ||
onboardingConfig = await getOnboardingConfig(config); | ||
expect(mockedPresets.getPreset).toHaveBeenCalledTimes(1); | ||
expect(JSON.parse(onboardingConfig).extends[0]).toEqual( | ||
'local>some/renovate-config' | ||
); | ||
}); | ||
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(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(JSON.parse(onboardingConfig)).toEqual(config.onboardingConfig); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,35 @@ | ||
import { RenovateConfig } from '../../../../config'; | ||
import { getPreset } from '../../../../config/presets'; | ||
import { PRESET_DEP_NOT_FOUND } from '../../../../config/presets/util'; | ||
import { logger } from '../../../../logger'; | ||
import { clone } from '../../../../util/clone'; | ||
|
||
export function getOnboardingConfig(config: RenovateConfig): string { | ||
const onboardingConfig = clone(config.onboardingConfig); | ||
export async function getOnboardingConfig( | ||
config: RenovateConfig | ||
): Promise<string> { | ||
let onboardingConfig = clone(config.onboardingConfig); | ||
|
||
let organizationConfigRepoExists = false; | ||
const organizationConfigPresetName = `local>${ | ||
config.repository.split('/')[0] | ||
}/renovate-config`; | ||
|
||
try { | ||
await getPreset(organizationConfigPresetName, config); | ||
organizationConfigRepoExists = true; | ||
} catch (err) { | ||
if (err.message !== PRESET_DEP_NOT_FOUND) { | ||
logger.warn({ err }, 'Unknown error fetching default owner preset'); | ||
} | ||
// Organization preset did not exist | ||
} | ||
if (organizationConfigRepoExists) { | ||
onboardingConfig = { | ||
$schema: 'https://docs.renovatebot.com/renovate-schema.json', | ||
extends: [organizationConfigPresetName], | ||
}; | ||
} | ||
|
||
logger.debug({ config: onboardingConfig }, 'onboarding config'); | ||
return JSON.stringify(onboardingConfig, null, 2) + '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters