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

View file

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

View file

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

View file

@ -72,7 +72,7 @@ export async function detectRepoFileConfig(): Promise<RepoFileConfig> {
if (configFileRaw) {
let configFileParsed = parseJson(configFileRaw, configFileName) as any;
if (configFileName !== 'package.json') {
return { configFileName, configFileRaw, configFileParsed };
return { configFileName, configFileParsed };
}
configFileParsed = configFileParsed.renovate;
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;
if (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));
return { configFileName, configFileRaw, configFileParsed };
return { configFileName, configFileParsed };
}
export function checkForRepoConfigError(repoConfig: RepoFileConfig): void {

View file

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