mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-28 15:36:27 +00:00
Merge ca5e135c5b
into da5c5ed3f6
This commit is contained in:
commit
ee84833586
4 changed files with 78 additions and 32 deletions
|
@ -1,13 +1,14 @@
|
||||||
|
import { codeBlock } from 'common-tags';
|
||||||
import type { Indent } from 'detect-indent';
|
import type { Indent } from 'detect-indent';
|
||||||
import { Fixtures } from '../../../../../test/fixtures';
|
import { Fixtures } from '../../../../../test/fixtures';
|
||||||
import type { RenovateConfig } from '../../../../../test/util';
|
import type { RenovateConfig } from '../../../../../test/util';
|
||||||
import { partial } from '../../../../../test/util';
|
import { fs, partial, scm } from '../../../../../test/util';
|
||||||
import { getConfig } from '../../../../config/defaults';
|
import { getConfig } from '../../../../config/defaults';
|
||||||
import { scm } from '../../../../modules/platform/scm';
|
|
||||||
import { createConfigMigrationBranch } from './create';
|
import { createConfigMigrationBranch } from './create';
|
||||||
import { MigratedDataFactory } from './migrated-data';
|
import { MigratedDataFactory } from './migrated-data';
|
||||||
import type { MigratedData } from './migrated-data';
|
import type { MigratedData } from './migrated-data';
|
||||||
|
|
||||||
|
jest.mock('../../../../util/fs');
|
||||||
jest.mock('../../../../util/git');
|
jest.mock('../../../../util/git');
|
||||||
|
|
||||||
describe('workers/repository/config-migration/branch/create', () => {
|
describe('workers/repository/config-migration/branch/create', () => {
|
||||||
|
@ -79,6 +80,42 @@ describe('workers/repository/config-migration/branch/create', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('migrates renovate config in package.json', async () => {
|
||||||
|
fs.readLocalFile.mockResolvedValueOnce(codeBlock`
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"xmldoc": "1.0.0"
|
||||||
|
},
|
||||||
|
"renovate": ${renovateConfig}
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
scm.getFileList.mockResolvedValueOnce([]);
|
||||||
|
await createConfigMigrationBranch(config, {
|
||||||
|
...migratedConfigData,
|
||||||
|
filename: 'package.json',
|
||||||
|
});
|
||||||
|
expect(scm.checkoutBranch).toHaveBeenCalledWith(config.defaultBranch);
|
||||||
|
expect(scm.commitAndPush).toHaveBeenCalledWith({
|
||||||
|
branchName: 'renovate/migrate-config',
|
||||||
|
baseBranch: 'dev',
|
||||||
|
files: [
|
||||||
|
{
|
||||||
|
type: 'addition',
|
||||||
|
path: 'renovate.json',
|
||||||
|
contents: renovateConfig,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'addition',
|
||||||
|
path: 'package.json',
|
||||||
|
contents: '{"dependencies":{"xmldoc":"1.0.0"}}',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
message: 'Migrate config renovate.json',
|
||||||
|
platformCommit: 'auto',
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('applies the commitMessagePrefix value', () => {
|
describe('applies the commitMessagePrefix value', () => {
|
||||||
it('to the default commit message', async () => {
|
it('to the default commit message', async () => {
|
||||||
config.commitMessagePrefix = 'PREFIX:';
|
config.commitMessagePrefix = 'PREFIX:';
|
||||||
|
|
|
@ -2,9 +2,12 @@ import { GlobalConfig } from '../../../../config/global';
|
||||||
import type { RenovateConfig } from '../../../../config/types';
|
import type { RenovateConfig } from '../../../../config/types';
|
||||||
import { logger } from '../../../../logger';
|
import { logger } from '../../../../logger';
|
||||||
import { scm } from '../../../../modules/platform/scm';
|
import { scm } from '../../../../modules/platform/scm';
|
||||||
|
import { parseJson } from '../../../../util/common';
|
||||||
|
import { readLocalFile } from '../../../../util/fs';
|
||||||
|
import type { FileChange } from '../../../../util/git/types';
|
||||||
import { getMigrationBranchName } from '../common';
|
import { getMigrationBranchName } from '../common';
|
||||||
import { ConfigMigrationCommitMessageFactory } from './commit-message';
|
import { ConfigMigrationCommitMessageFactory } from './commit-message';
|
||||||
import { MigratedDataFactory } from './migrated-data';
|
import { MigratedDataFactory, applyPrettierFormatting } from './migrated-data';
|
||||||
import type { MigratedData } from './migrated-data';
|
import type { MigratedData } from './migrated-data';
|
||||||
|
|
||||||
export async function createConfigMigrationBranch(
|
export async function createConfigMigrationBranch(
|
||||||
|
@ -12,7 +15,10 @@ export async function createConfigMigrationBranch(
|
||||||
migratedConfigData: MigratedData,
|
migratedConfigData: MigratedData,
|
||||||
): Promise<string | null> {
|
): Promise<string | null> {
|
||||||
logger.debug('createConfigMigrationBranch()');
|
logger.debug('createConfigMigrationBranch()');
|
||||||
const configFileName = migratedConfigData.filename;
|
const pJsonMigration = migratedConfigData.filename === 'package.json';
|
||||||
|
const configFileName = pJsonMigration
|
||||||
|
? 'renovate.json'
|
||||||
|
: migratedConfigData.filename;
|
||||||
logger.debug('Creating config migration branch');
|
logger.debug('Creating config migration branch');
|
||||||
|
|
||||||
const commitMessageFactory = new ConfigMigrationCommitMessageFactory(
|
const commitMessageFactory = new ConfigMigrationCommitMessageFactory(
|
||||||
|
@ -31,16 +37,40 @@ export async function createConfigMigrationBranch(
|
||||||
await scm.checkoutBranch(config.defaultBranch!);
|
await scm.checkoutBranch(config.defaultBranch!);
|
||||||
const contents =
|
const contents =
|
||||||
await MigratedDataFactory.applyPrettierFormatting(migratedConfigData);
|
await MigratedDataFactory.applyPrettierFormatting(migratedConfigData);
|
||||||
return scm.commitAndPush({
|
|
||||||
baseBranch: config.baseBranch,
|
const files: FileChange[] = [
|
||||||
branchName: getMigrationBranchName(config),
|
|
||||||
files: [
|
|
||||||
{
|
{
|
||||||
type: 'addition',
|
type: 'addition',
|
||||||
path: configFileName,
|
path: configFileName,
|
||||||
contents,
|
contents,
|
||||||
},
|
},
|
||||||
],
|
];
|
||||||
|
|
||||||
|
if (pJsonMigration) {
|
||||||
|
const pJson = parseJson(
|
||||||
|
await readLocalFile('package.json', 'utf8'),
|
||||||
|
'package.json',
|
||||||
|
) as any;
|
||||||
|
if (pJson?.renovate) {
|
||||||
|
delete pJson.renovate;
|
||||||
|
}
|
||||||
|
const pJsonContent = await applyPrettierFormatting(
|
||||||
|
'package.json',
|
||||||
|
JSON.stringify(pJson, undefined, migratedConfigData.indent.indent),
|
||||||
|
'json',
|
||||||
|
migratedConfigData.indent,
|
||||||
|
);
|
||||||
|
files.push({
|
||||||
|
type: 'addition',
|
||||||
|
path: 'package.json',
|
||||||
|
contents: pJsonContent,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return scm.commitAndPush({
|
||||||
|
baseBranch: config.baseBranch,
|
||||||
|
branchName: getMigrationBranchName(config),
|
||||||
|
files,
|
||||||
message: commitMessage.toString(),
|
message: commitMessage.toString(),
|
||||||
platformCommit: config.platformCommit,
|
platformCommit: config.platformCommit,
|
||||||
force: true,
|
force: true,
|
||||||
|
|
|
@ -46,19 +46,6 @@ describe('workers/repository/config-migration/index', () => {
|
||||||
expect(ensureConfigMigrationPr).toHaveBeenCalledTimes(0);
|
expect(ensureConfigMigrationPr).toHaveBeenCalledTimes(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('skips pr creation if config found in package.json', async () => {
|
|
||||||
const branchList: string[] = [];
|
|
||||||
mockedFunction(MigratedDataFactory.getAsync).mockResolvedValue({
|
|
||||||
content,
|
|
||||||
indent: partial<Indent>(),
|
|
||||||
filename: 'package.json',
|
|
||||||
});
|
|
||||||
const res = await configMigration(config, branchList);
|
|
||||||
expect(res).toMatchObject({ result: 'no-migration' });
|
|
||||||
expect(checkConfigMigrationBranch).toHaveBeenCalledTimes(0);
|
|
||||||
expect(ensureConfigMigrationPr).toHaveBeenCalledTimes(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('creates migration pr if needed', async () => {
|
it('creates migration pr if needed', async () => {
|
||||||
const branchList: string[] = [];
|
const branchList: string[] = [];
|
||||||
mockedFunction(checkConfigMigrationBranch).mockResolvedValue({
|
mockedFunction(checkConfigMigrationBranch).mockResolvedValue({
|
||||||
|
|
|
@ -27,14 +27,6 @@ export async function configMigration(
|
||||||
return { result: 'no-migration' };
|
return { result: 'no-migration' };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (migratedConfigData.filename === 'package.json') {
|
|
||||||
logger.debug(
|
|
||||||
' Using package.json for Renovate config is deprecated - please use a dedicated configuration file instead. Skipping config migration.',
|
|
||||||
);
|
|
||||||
MigratedDataFactory.reset();
|
|
||||||
return { result: 'no-migration' };
|
|
||||||
}
|
|
||||||
|
|
||||||
const res = await checkConfigMigrationBranch(config, migratedConfigData);
|
const res = await checkConfigMigrationBranch(config, migratedConfigData);
|
||||||
|
|
||||||
// migration needed but not demanded by user
|
// migration needed but not demanded by user
|
||||||
|
|
Loading…
Reference in a new issue