Skip to content

Commit

Permalink
refactor(migrations): automergeMajor (#14634)
Browse files Browse the repository at this point in the history
  • Loading branch information
pret-a-porter committed Mar 13, 2022
1 parent 90e5182 commit 0b54d5e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
4 changes: 0 additions & 4 deletions lib/config/migration.ts
Expand Up @@ -202,10 +202,6 @@ export function migrateConfig(
migratedConfig.minor = migratedConfig.minor || {};
migratedConfig.minor.automerge = !!val;
delete migratedConfig[key];
} else if (key === 'automergeMajor') {
migratedConfig.major = migratedConfig.major || {};
migratedConfig.major.automerge = !!val;
delete migratedConfig[key];
} else if (key === 'separateMajorReleases') {
delete migratedConfig.separateMultipleMajor;
migratedConfig.separateMajorMinor = val;
Expand Down
47 changes: 47 additions & 0 deletions lib/config/migrations/custom/automerge-major-migration.spec.ts
@@ -0,0 +1,47 @@
import { AutomergeMajorMigration } from './automerge-major-migration';

describe('config/migrations/custom/automerge-major-migration', () => {
it('should migrate value to object', () => {
expect(AutomergeMajorMigration).toMigrate(
{
automergeMajor: 'some-value',
},
{
major: {
automerge: true,
},
}
);
});

it('should migrate value to object and concat with existing minor object', () => {
expect(AutomergeMajorMigration).toMigrate(
{
automergeMajor: 'some-value',
major: {
matchFiles: ['test'],
},
},
{
major: {
automerge: true,
matchFiles: ['test'],
},
}
);
});

it('should ignore non object minor value', () => {
expect(AutomergeMajorMigration).toMigrate(
{
automergeMajor: 'some-value',
major: null,
},
{
major: {
automerge: true,
},
}
);
});
});
15 changes: 15 additions & 0 deletions lib/config/migrations/custom/automerge-major-migration.ts
@@ -0,0 +1,15 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class AutomergeMajorMigration extends AbstractMigration {
override readonly deprecated = true;
override readonly propertyName = 'automergeMajor';

override run(value: unknown): void {
const major = this.get('major');

const newMajor = is.object(major) ? major : {};
newMajor.automerge = Boolean(value);
this.setHard('major', newMajor);
}
}
2 changes: 2 additions & 0 deletions lib/config/migrations/migrations-service.ts
Expand Up @@ -2,6 +2,7 @@ import { dequal } from 'dequal';
import type { RenovateConfig } from '../types';
import { RemovePropertyMigration } from './base/remove-property-migration';
import { RenamePropertyMigration } from './base/rename-property-migration';
import { AutomergeMajorMigration } from './custom/automerge-major-migration';
import { AutomergeTypeMigration } from './custom/automerge-type-migration';
import { BinarySourceMigration } from './custom/binary-source-migration';
import { CompatibilityMigration } from './custom/compatibility-migration';
Expand Down Expand Up @@ -55,6 +56,7 @@ export class MigrationsService {
]);

static readonly customMigrations: ReadonlyArray<MigrationConstructor> = [
AutomergeMajorMigration,
AutomergeTypeMigration,
BinarySourceMigration,
CompatibilityMigration,
Expand Down

0 comments on commit 0b54d5e

Please sign in to comment.