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

refactor: migration semantic prefix #16218

Merged
10 changes: 0 additions & 10 deletions lib/config/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,6 @@ export function migrateConfig(config: RenovateConfig): MigratedConfig {
regEx(/{{depNameShort}}/g),
'{{depName}}'
);
} else if (key === 'semanticPrefix' && is.string(val)) {
delete migratedConfig.semanticPrefix;
let [text] = val.split(':') as any; // TODO: fixme
text = text.split('(');
[migratedConfig.semanticCommitType] = text;
if (text.length > 1) {
[migratedConfig.semanticCommitScope] = text[1].split(')');
} else {
migratedConfig.semanticCommitScope = null;
}
} else if (is.string(val) && val.startsWith('{{semanticPrefix}}')) {
migratedConfig[key] = val.replace(
'{{semanticPrefix}}',
Expand Down
39 changes: 39 additions & 0 deletions lib/config/migrations/custom/semantic-prefix-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { SemanticPrefixMigration } from './semantic-prefix-migration';

describe('config/migrations/custom/semantic-prefix-migration', () => {
it('should work', () => {
expect(SemanticPrefixMigration).toMigrate(
{
semanticPrefix: 'fix(deps): ',
} as any,
{ semanticCommitType: 'fix', semanticCommitScope: 'deps' }
);
});

it('should remove non-string values', () => {
expect(SemanticPrefixMigration).toMigrate(
{
semanticPrefix: true,
} as any,
{}
);
});

it('should migrate prefix with no-scope to null', () => {
expect(SemanticPrefixMigration).toMigrate(
{
semanticPrefix: 'fix: ',
} as any,
{ semanticCommitType: 'fix', semanticCommitScope: null }
);
});

it('works for random string', () => {
expect(SemanticPrefixMigration).toMigrate(
{
semanticPrefix: 'test',
} as any,
{ semanticCommitType: 'test', semanticCommitScope: null }
);
});
});
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions lib/config/migrations/custom/semantic-prefix-migration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import is from '@sindresorhus/is';
import { AbstractMigration } from '../base/abstract-migration';

export class SemanticPrefixMigration extends AbstractMigration {
override readonly deprecated = true;
viceice marked this conversation as resolved.
Show resolved Hide resolved
override readonly propertyName = 'semanticPrefix';

override run(value: unknown): void {
if (is.string(value)) {
const [text] = value.split(':');
RahulGautamSingh marked this conversation as resolved.
Show resolved Hide resolved
const [type, scope] = text.split('(');
this.setSafely('semanticCommitType', type);
this.setSafely('semanticCommitScope', scope ? scope.split(')')[0] : null);
}
}
}
2 changes: 2 additions & 0 deletions lib/config/migrations/migrations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { RequireConfigMigration } from './custom/require-config-migration';
import { RequiredStatusChecksMigration } from './custom/required-status-checks-migration';
import { ScheduleMigration } from './custom/schedule-migration';
import { SemanticCommitsMigration } from './custom/semantic-commits-migration';
import { SemanticPrefixMigration } from './custom/semantic-prefix-migration';
import { SeparateMajorReleasesMigration } from './custom/separate-major-release-migration';
import { SeparateMultipleMajorMigration } from './custom/separate-multiple-major-migration';
import { SuppressNotificationsMigration } from './custom/suppress-notifications-migration';
Expand Down Expand Up @@ -119,6 +120,7 @@ export class MigrationsService {
VersionStrategyMigration,
DryRunMigration,
RequireConfigMigration,
SemanticPrefixMigration,
];

static run(originalConfig: RenovateConfig): RenovateConfig {
Expand Down