Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(migrations): split #13499

Merged
merged 24 commits into from
Jan 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f4d3d19
refactor(migrations): implemented migration validator
pret-a-porter Dec 12, 2021
d974833
refactor(migrations): semantic commits
pret-a-porter Dec 12, 2021
7a283fd
refactor(migrations): enabled managers
pret-a-porter Dec 12, 2021
087a2b9
refactor(migrations): pin versions
pret-a-porter Dec 12, 2021
1215dd3
refactor(migrations): introduce deprecated flag
pret-a-porter Dec 12, 2021
aa12a1c
refactor(migrations): rebase stale prs
pret-a-porter Dec 12, 2021
a43f277
refactor(migrations): tidy
pret-a-porter Dec 12, 2021
1c9c0b7
refactor(migrations): improve validator
pret-a-porter Dec 12, 2021
3232d37
refactor(migrations): rebase conflicted prs
pret-a-porter Dec 12, 2021
909c98c
refactor(migrations): fix coverage
pret-a-porter Dec 12, 2021
b0d345c
Merge branch 'main' into refactor/migration_validator
pret-a-porter Dec 12, 2021
64b5a67
refactor(migrations): fix coverage
pret-a-porter Dec 12, 2021
64e61f5
refactor(migrations): fix build
pret-a-porter Dec 12, 2021
c69be7f
Merge branch 'main' into refactor/migration_validator
pret-a-porter Dec 19, 2021
beaad84
refactor: fix launch.json
pret-a-porter Dec 19, 2021
79a6cfc
Merge branch 'renovatebot:main' into refactor/migrations_temp
pret-a-porter Dec 28, 2021
1499b70
Merge branch 'main' into refactor/migrations_temp
pret-a-porter Jan 11, 2022
066112f
refactor: adjust migrations
pret-a-porter Jan 11, 2022
728ee61
feat: add override modifier
pret-a-porter Jan 11, 2022
d739b74
Apply suggestions from code review
rarkins Jan 12, 2022
5ba375f
Merge branch 'main' into feat/split_migrations
pret-a-porter Jan 12, 2022
706faf5
feat: fix unit test
pret-a-porter Jan 12, 2022
67bb0ca
Merge branch 'main' into feat/split_migrations
JamieMagee Jan 13, 2022
8024c4d
Merge branch 'main' into feat/split_migrations
rarkins Jan 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 0 additions & 29 deletions lib/config/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,35 +452,6 @@ describe('config/migration', () => {
});
expect(isMigrated).toBeTrue();
});
it('it migrates semanticCommits', () => {
let config: TestRenovateConfig;
let res: MigratedConfig;

config = { semanticCommits: true as never };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBeTrue();
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'enabled' });

config = { semanticCommits: false as never };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBeTrue();
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'disabled' });

config = { semanticCommits: null as never };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBeTrue();
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'auto' });

config = { semanticCommits: 'enabled' };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBeFalse();
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'enabled' });

config = { semanticCommits: 'disabled' };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBeFalse();
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'disabled' });
});

it('it migrates preset strings to array', () => {
let config: TestRenovateConfig;
Expand Down
38 changes: 0 additions & 38 deletions lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,6 @@ export function migrateConfig(
migratedConfig[newKey] = true;
}
delete migratedConfig[key];
} else if (key === 'semanticCommits') {
if (val === true) {
migratedConfig.semanticCommits = 'enabled';
} else if (val === false) {
migratedConfig.semanticCommits = 'disabled';
} else if (val !== 'enabled' && val !== 'disabled') {
migratedConfig.semanticCommits = 'auto';
}
} else if (key === 'enabledManagers' && is.array(val)) {
// Replace yarn with npm, since yarn actually uses npm as package manager
migratedConfig.enabledManagers = migratedConfig.enabledManagers.map(
(element) => (element === 'yarn' ? 'npm' : element)
);
} else if (parentKey === 'hostRules' && key === 'platform') {
migratedConfig.hostType = val;
delete migratedConfig.platform;
Expand Down Expand Up @@ -150,13 +137,6 @@ export function migrateConfig(
delete depTypePackageRule.packageRules;
migratedConfig.packageRules.push(depTypePackageRule);
delete migratedConfig[key];
} else if (key === 'pinVersions') {
delete migratedConfig.pinVersions;
if (val === true) {
migratedConfig.rangeStrategy = 'pin';
} else if (val === false) {
migratedConfig.rangeStrategy = 'replace';
}
} else if (is.string(val) && val.includes('{{baseDir}}')) {
migratedConfig[key] = val.replace(
regEx(/{{baseDir}}/g),
Expand All @@ -169,24 +149,6 @@ export function migrateConfig(
);
} else if (key === 'gitFs') {
delete migratedConfig.gitFs;
} else if (key === 'rebaseStalePrs') {
delete migratedConfig.rebaseStalePrs;
if (!migratedConfig.rebaseWhen) {
if (val === null) {
migratedConfig.rebaseWhen = 'auto';
}
if (val === true) {
migratedConfig.rebaseWhen = 'behind-base-branch';
}
if (val === false) {
migratedConfig.rebaseWhen = 'conflicted';
}
}
} else if (key === 'rebaseConflictedPrs') {
delete migratedConfig.rebaseConflictedPrs;
if (val === false) {
migratedConfig.rebaseWhen = 'never';
}
} else if (key === 'ignoreNpmrcFile') {
delete migratedConfig.ignoreNpmrcFile;
if (!is.string(migratedConfig.npmrc)) {
Expand Down
14 changes: 14 additions & 0 deletions lib/config/migrations/custom/enabled-managers-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { EnabledManagersMigration } from './enabled-managers-migration';

describe('config/migrations/custom/enabled-managers-migration', () => {
it('should replace yarn with npm', () => {
expect(EnabledManagersMigration).toMigrate(
{
enabledManagers: ['test1', 'yarn', 'test2'],
},
{
enabledManagers: ['test1', 'npm', 'test2'],
}
);
});
});
15 changes: 15 additions & 0 deletions lib/config/migrations/custom/enabled-managers-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class EnabledManagersMigration extends AbstractMigration {
readonly propertyName = 'enabledManagers';

override run(value: string[]): void {
if (is.array(value)) {
const newValue = value.map((manager) =>
manager === 'yarn' ? 'npm' : manager
);
this.rewrite(newValue);
}
}
}
25 changes: 25 additions & 0 deletions lib/config/migrations/custom/pin-versions-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { PinVersionsMigration } from './pin-versions-migration';

describe('config/migrations/custom/pin-versions-migration', () => {
it('should migrate true', () => {
expect(PinVersionsMigration).toMigrate(
{
pinVersions: true,
},
{
rangeStrategy: 'pin',
}
);
});

it('should migrate false', () => {
expect(PinVersionsMigration).toMigrate(
{
pinVersions: false,
},
{
rangeStrategy: 'replace',
}
);
});
});
13 changes: 13 additions & 0 deletions lib/config/migrations/custom/pin-versions-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class PinVersionsMigration extends AbstractMigration {
override readonly deprecated = true;
readonly propertyName = 'pinVersions';

override run(value): void {
if (is.boolean(value)) {
this.setSafely('rangeStrategy', value ? 'pin' : 'replace');
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { RebaseConflictedPrs } from './rebase-conflicted-prs-migration';

describe('config/migrations/custom/rebase-conflicted-prs-migration', () => {
it('should migrate false', () => {
expect(RebaseConflictedPrs).toMigrate(
{
rebaseConflictedPrs: false,
},
{
rebaseWhen: 'never',
}
);
});
});
12 changes: 12 additions & 0 deletions lib/config/migrations/custom/rebase-conflicted-prs-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { AbstractMigration } from '../base/abstract-migration';

export class RebaseConflictedPrs extends AbstractMigration {
override readonly deprecated = true;
readonly propertyName = 'rebaseConflictedPrs';

override run(value): void {
if (value === false) {
this.setSafely('rebaseWhen', 'never');
}
}
}
36 changes: 36 additions & 0 deletions lib/config/migrations/custom/rebase-stale-prs-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { RebaseStalePrsMigration } from './rebase-stale-prs-migration';

describe('config/migrations/custom/rebase-stale-prs-migration', () => {
it('should migrate true', () => {
expect(RebaseStalePrsMigration).toMigrate(
{
rebaseStalePrs: true,
},
{
rebaseWhen: 'behind-base-branch',
}
);
});

it('should migrate false', () => {
expect(RebaseStalePrsMigration).toMigrate(
{
rebaseStalePrs: false,
},
{
rebaseWhen: 'conflicted',
}
);
});

it('should migrate null', () => {
expect(RebaseStalePrsMigration).toMigrate(
{
rebaseStalePrs: null,
},
{
rebaseWhen: 'auto',
}
);
});
});
24 changes: 24 additions & 0 deletions lib/config/migrations/custom/rebase-stale-prs-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class RebaseStalePrsMigration extends AbstractMigration {
override readonly deprecated = true;
readonly propertyName = 'rebaseStalePrs';

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

if (rebaseConflictedPrs !== false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the double negative is a little confusing

Suggested change
if (rebaseConflictedPrs !== false) {
if (rebaseConflictedPrs === true) {

or

Suggested change
if (rebaseConflictedPrs !== false) {
if (rebaseConflictedPrs) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I re-read this, I realise that rebaseConflictedPrs is boolean | undefined so you'd need rebaseConflictedPrs === true || rebaseConflictedPrs === undefined. Gotta love that trinary logic 😅

if (is.boolean(value)) {
this.setSafely(
'rebaseWhen',
value ? 'behind-base-branch' : 'conflicted'
);
}

if (is.null_(value)) {
this.setSafely('rebaseWhen', 'auto');
}
}
}
}
59 changes: 59 additions & 0 deletions lib/config/migrations/custom/semantic-commits-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { SemanticCommitsMigration } from './semantic-commits-migration';

describe('config/migrations/custom/semantic-commits-migration', () => {
it('should migrate true to "enabled"', () => {
expect(SemanticCommitsMigration).toMigrate(
{
semanticCommits: true,
} as any,
JamieMagee marked this conversation as resolved.
Show resolved Hide resolved
{ semanticCommits: 'enabled' }
);
});

it('should migrate false to "disabled"', () => {
expect(SemanticCommitsMigration).toMigrate(
{
semanticCommits: false,
} as any,
{ semanticCommits: 'disabled' }
);
});

it('should migrate null to "auto"', () => {
expect(SemanticCommitsMigration).toMigrate(
{
semanticCommits: null,
} as any,
{ semanticCommits: 'auto' }
);
});

it('should migrate random string to "auto"', () => {
expect(SemanticCommitsMigration).toMigrate(
{
semanticCommits: 'test',
} as any,
{ semanticCommits: 'auto' }
);
});

it('should not migrate valid enabled config', () => {
expect(SemanticCommitsMigration).toMigrate(
{
semanticCommits: 'enabled',
} as any,
{ semanticCommits: 'enabled' },
false
);
});

it('should not migrate valid disabled config', () => {
expect(SemanticCommitsMigration).toMigrate(
{
semanticCommits: 'disabled',
} as any,
{ semanticCommits: 'disabled' },
false
);
});
});
14 changes: 14 additions & 0 deletions lib/config/migrations/custom/semantic-commits-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class SemanticCommitsMigration extends AbstractMigration {
readonly propertyName = 'semanticCommits';

override run(value): void {
if (is.boolean(value)) {
this.rewrite(value ? 'enabled' : 'disabled');
} else if (value !== 'enabled' && value !== 'disabled') {
this.rewrite('auto');
}
}
}
10 changes: 10 additions & 0 deletions lib/config/migrations/migrations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import type { RenovateConfig } from '../types';
import { RemovePropertyMigration } from './base/remove-property-migration';
import { RenamePropertyMigration } from './base/rename-property-migration';
import { BinarySourceMigration } from './custom/binary-source-migration';
import { EnabledManagersMigration } from './custom/enabled-managers-migration';
import { GoModTidyMigration } from './custom/go-mod-tidy-migration';
import { IgnoreNodeModulesMigration } from './custom/ignore-node-modules-migration';
import { PinVersionsMigration } from './custom/pin-versions-migration';
import { RebaseConflictedPrs } from './custom/rebase-conflicted-prs-migration';
import { RebaseStalePrsMigration } from './custom/rebase-stale-prs-migration';
import { RequiredStatusChecksMigration } from './custom/required-status-checks-migration';
import { SemanticCommitsMigration } from './custom/semantic-commits-migration';
import { TrustLevelMigration } from './custom/trust-level-migration';
import type { Migration, MigrationConstructor } from './types';

Expand Down Expand Up @@ -37,9 +42,14 @@ export class MigrationsService {

static readonly customMigrations: ReadonlyArray<MigrationConstructor> = [
BinarySourceMigration,
EnabledManagersMigration,
GoModTidyMigration,
IgnoreNodeModulesMigration,
PinVersionsMigration,
RebaseConflictedPrs,
RebaseStalePrsMigration,
RequiredStatusChecksMigration,
SemanticCommitsMigration,
TrustLevelMigration,
];

Expand Down