refactor: fetch raw config from within config migration (#26891)

This commit is contained in:
Rhys Arkins 2024-01-28 14:36:06 +01:00 committed by GitHub
parent 39d01251b2
commit 535c7ae1a1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 6 additions and 22 deletions

View file

@ -16,8 +16,6 @@ jest.mock('../../../../util/json-writer');
jest.mock('../../init/merge'); jest.mock('../../init/merge');
jest.mock('detect-indent'); jest.mock('detect-indent');
const rawNonMigrated = Fixtures.get('./renovate.json');
const rawNonMigratedJson5 = Fixtures.get('./renovate.json5');
const migratedData = Fixtures.getJson('./migrated-data.json'); const migratedData = Fixtures.getJson('./migrated-data.json');
const migratedDataJson5 = Fixtures.getJson('./migrated-data.json5'); const migratedDataJson5 = Fixtures.getJson('./migrated-data.json5');
const migratedConfigObj = Fixtures.getJson('./migrated.json'); const migratedConfigObj = Fixtures.getJson('./migrated.json');
@ -35,7 +33,6 @@ describe('workers/repository/config-migration/branch/migrated-data', () => {
}); });
mockedFunction(detectRepoFileConfig).mockResolvedValue({ mockedFunction(detectRepoFileConfig).mockResolvedValue({
configFileName: 'renovate.json', configFileName: 'renovate.json',
configFileRaw: rawNonMigrated,
}); });
mockedFunction(migrateConfig).mockReturnValue({ mockedFunction(migrateConfig).mockReturnValue({
isMigrated: true, isMigrated: true,
@ -102,7 +99,6 @@ describe('workers/repository/config-migration/branch/migrated-data', () => {
it('Migrate a JSON5 config file', async () => { it('Migrate a JSON5 config file', async () => {
mockedFunction(detectRepoFileConfig).mockResolvedValueOnce({ mockedFunction(detectRepoFileConfig).mockResolvedValueOnce({
configFileName: 'renovate.json5', configFileName: 'renovate.json5',
configFileRaw: rawNonMigratedJson5,
}); });
MigratedDataFactory.reset(); MigratedDataFactory.reset();
await expect(MigratedDataFactory.getAsync()).resolves.toEqual( await expect(MigratedDataFactory.getAsync()).resolves.toEqual(
@ -131,7 +127,6 @@ describe('workers/repository/config-migration/branch/migrated-data', () => {
}); });
mockedFunction(detectRepoFileConfig).mockResolvedValueOnce({ mockedFunction(detectRepoFileConfig).mockResolvedValueOnce({
configFileName: 'renovate.json', configFileName: 'renovate.json',
configFileRaw: rawNonMigrated,
}); });
mockedFunction(migrateConfig).mockReturnValueOnce({ mockedFunction(migrateConfig).mockReturnValueOnce({
isMigrated: true, isMigrated: true,

View file

@ -130,11 +130,8 @@ export class MigratedDataFactory {
private static async build(): Promise<MigratedData | null> { private static async build(): Promise<MigratedData | null> {
let res: MigratedData | null = null; let res: MigratedData | null = null;
try { try {
const { const { configFileName, configFileParsed = {} } =
configFileName, await detectRepoFileConfig();
configFileRaw: raw,
configFileParsed = {},
} = await detectRepoFileConfig();
// get migrated config // get migrated config
const { isMigrated, migratedConfig } = migrateConfig(configFileParsed); const { isMigrated, migratedConfig } = migrateConfig(configFileParsed);
@ -147,6 +144,7 @@ export class MigratedDataFactory {
// indent defaults to 2 spaces // indent defaults to 2 spaces
// TODO #22198 // TODO #22198
const raw = await readLocalFile(configFileName!, 'utf8');
const indent = detectIndent(raw!); const indent = detectIndent(raw!);
const indentSpace = indent.indent ?? ' '; const indentSpace = indent.indent ?? ' ';
const filename = configFileName!; const filename = configFileName!;

View file

@ -124,7 +124,6 @@ describe('workers/repository/init/merge', () => {
configFileParsed: { configFileParsed: {
schema: 'https://docs.renovate.com', schema: 'https://docs.renovate.com',
}, },
configFileRaw: undefined,
}); });
}); });
@ -199,7 +198,6 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({ expect(await detectRepoFileConfig()).toEqual({
configFileName: 'renovate.json5', configFileName: 'renovate.json5',
configFileParsed: {}, configFileParsed: {},
configFileRaw,
}); });
}); });
@ -212,7 +210,6 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({ expect(await detectRepoFileConfig()).toEqual({
configFileName: '.github/renovate.json', configFileName: '.github/renovate.json',
configFileParsed: {}, configFileParsed: {},
configFileRaw: '{}',
}); });
}); });
@ -225,7 +222,6 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({ expect(await detectRepoFileConfig()).toEqual({
configFileName: '.gitlab/renovate.json', configFileName: '.gitlab/renovate.json',
configFileParsed: {}, configFileParsed: {},
configFileRaw: '{}',
}); });
}); });
@ -236,14 +232,12 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({ expect(await detectRepoFileConfig()).toEqual({
configFileName: '.renovaterc.json', configFileName: '.renovaterc.json',
configFileParsed: {}, configFileParsed: {},
configFileRaw: '{}',
}); });
expect(await detectRepoFileConfig()).toEqual({ expect(await detectRepoFileConfig()).toEqual({
configFileName: '.renovaterc.json', configFileName: '.renovaterc.json',
configFileParsed: { configFileParsed: {
something: 'new', something: 'new',
}, },
configFileRaw: '{"something":"new"}',
}); });
}); });
@ -254,14 +248,12 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({ expect(await detectRepoFileConfig()).toEqual({
configFileName: '.renovaterc.json5', configFileName: '.renovaterc.json5',
configFileParsed: {}, configFileParsed: {},
configFileRaw: '{}',
}); });
expect(await detectRepoFileConfig()).toEqual({ expect(await detectRepoFileConfig()).toEqual({
configFileName: '.renovaterc.json5', configFileName: '.renovaterc.json5',
configFileParsed: { configFileParsed: {
something: 'new', something: 'new',
}, },
configFileRaw: '{"something":"new"}',
}); });
}); });
}); });

View file

@ -72,7 +72,7 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
if (configFileRaw) { if (configFileRaw) {
let configFileParsed = parseJson(configFileRaw, configFileName) as any; let configFileParsed = parseJson(configFileRaw, configFileName) as any;
if (configFileName !== 'package.json') { if (configFileName !== 'package.json') {
return { configFileName, configFileRaw, configFileParsed }; return { configFileName, configFileParsed };
} }
configFileParsed = configFileParsed.renovate; configFileParsed = configFileParsed.renovate;
return { configFileName, configFileParsed }; // don't return raw 'package.json' return { configFileName, configFileParsed }; // don't return raw 'package.json'
@ -103,7 +103,7 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
const parsedConfig = cachedConfig ? JSON.parse(cachedConfig) : undefined; const parsedConfig = cachedConfig ? JSON.parse(cachedConfig) : undefined;
if (parsedConfig) { if (parsedConfig) {
setOnboardingConfigDetails(configFileName, JSON.stringify(parsedConfig)); setOnboardingConfigDetails(configFileName, JSON.stringify(parsedConfig));
return { configFileName, configFileRaw, configFileParsed: parsedConfig }; return { configFileName, configFileParsed: parsedConfig };
} }
} }
@ -202,7 +202,7 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
} }
setOnboardingConfigDetails(configFileName, JSON.stringify(configFileParsed)); setOnboardingConfigDetails(configFileName, JSON.stringify(configFileParsed));
return { configFileName, configFileRaw, configFileParsed }; return { configFileName, configFileParsed };
} }
export function checkForRepoConfigError(repoConfig: RepoFileConfig): void { export function checkForRepoConfigError(repoConfig: RepoFileConfig): void {

View file

@ -5,7 +5,6 @@ export interface RepoConfigError {
export interface RepoFileConfig { export interface RepoFileConfig {
configFileName?: string; configFileName?: string;
configFileRaw?: string | null;
configFileParsed?: any; configFileParsed?: any;
configFileParseError?: RepoConfigError; configFileParseError?: RepoConfigError;
} }