Skip to content

Commit

Permalink
refactor: fetch raw config from within config migration (#26891)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Jan 28, 2024
1 parent 39d0125 commit 535c7ae
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 22 deletions.
Expand Up @@ -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');
Expand All @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
Expand Up @@ -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);
Expand All @@ -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!;
Expand Down
8 changes: 0 additions & 8 deletions lib/workers/repository/init/merge.spec.ts
Expand Up @@ -124,7 +124,6 @@ describe('workers/repository/init/merge', () => {
configFileParsed: {
schema: 'https://docs.renovate.com',
},
configFileRaw: undefined,
});
});

Expand Down Expand Up @@ -199,7 +198,6 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({
configFileName: 'renovate.json5',
configFileParsed: {},
configFileRaw,
});
});

Expand All @@ -212,7 +210,6 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({
configFileName: '.github/renovate.json',
configFileParsed: {},
configFileRaw: '{}',
});
});

Expand All @@ -225,7 +222,6 @@ describe('workers/repository/init/merge', () => {
expect(await detectRepoFileConfig()).toEqual({
configFileName: '.gitlab/renovate.json',
configFileParsed: {},
configFileRaw: '{}',
});
});

Expand All @@ -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"}',
});
});

Expand All @@ -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"}',
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions lib/workers/repository/init/merge.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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 };
}
}

Expand Down Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion lib/workers/repository/init/types.ts
Expand Up @@ -5,7 +5,6 @@ export interface RepoConfigError {

export interface RepoFileConfig {
configFileName?: string;
configFileRaw?: string | null;
configFileParsed?: any;
configFileParseError?: RepoConfigError;
}
Expand Down

0 comments on commit 535c7ae

Please sign in to comment.