fix: Revert "fix(config): Migrate semantic commit option to enum type (#7170)"

This reverts commit d2a5b7167b.
This commit is contained in:
Rhys Arkins 2020-09-11 12:43:49 +02:00
parent d2a5b7167b
commit d1d7901a0a
15 changed files with 25 additions and 57 deletions

View file

@ -52,7 +52,7 @@ export interface RenovateSharedConfig {
repositoryCache?: RepositoryCacheConfig;
requiredStatusChecks?: string[];
schedule?: string[];
semanticCommits?: 'auto' | 'enabled' | 'disabled';
semanticCommits?: boolean;
semanticCommitScope?: string;
semanticCommitType?: string;
suppressNotifications?: string[];

View file

@ -1084,9 +1084,8 @@ const options: RenovateOptions[] = [
{
name: 'semanticCommits',
description: 'Enable semantic commit prefixes for commits and PR titles',
type: 'string',
allowedValues: ['auto', 'enabled', 'disabled'],
default: 'auto',
type: 'boolean',
default: null,
},
{
name: 'semanticCommitType',

View file

@ -1,7 +1,6 @@
import { PLATFORM_TYPE_GITHUB } from '../constants/platforms';
import { getConfig } from './defaults';
import * as configMigration from './migration';
import { MigratedConfig } from './migration';
import { RenovateSharedConfig, RenovateConfig as _RenovateConfig } from '.';
const defaultConfig = getConfig();
@ -130,7 +129,7 @@ describe('config/migration', () => {
],
raiseDeprecationWarnings: false,
};
const parentConfig = { ...defaultConfig, semanticCommits: 'disabled' };
const parentConfig = { ...defaultConfig, semanticCommits: false };
const { isMigrated, migratedConfig } = configMigration.migrateConfig(
config,
parentConfig
@ -270,6 +269,7 @@ describe('config/migration', () => {
it('does not migrate config', () => {
const config: RenovateConfig = {
enabled: true,
semanticCommits: true,
separateMinorPatch: true,
};
const { isMigrated, migratedConfig } = configMigration.migrateConfig(
@ -403,24 +403,5 @@ describe('config/migration', () => {
expect(migratedConfig).toMatchSnapshot();
expect(isMigrated).toBe(true);
});
it('it migrates semanticCommits', () => {
let config: RenovateConfig;
let res: MigratedConfig;
config = { semanticCommits: true as never };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBe(true);
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'enabled' });
config = { semanticCommits: false as never };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBe(true);
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'disabled' });
config = { semanticCommits: null as never };
res = configMigration.migrateConfig(config);
expect(res.isMigrated).toBe(true);
expect(res.migratedConfig).toMatchObject({ semanticCommits: 'auto' });
});
});
});

View file

@ -101,15 +101,6 @@ export function migrateConfig(
migratedConfig.postUpdateOptions.push('gomodTidy');
}
delete migratedConfig.gomodTidy;
} else if (key === 'semanticCommits') {
isMigrated = true;
if (val === true) {
migratedConfig.semanticCommits = 'enabled';
} else if (val === false) {
migratedConfig.semanticCommits = 'disabled';
} else {
migratedConfig.semanticCommits = 'auto';
}
} else if (parentKey === 'hostRules' && key === 'platform') {
isMigrated = true;
migratedConfig.hostType = val;

View file

@ -393,7 +393,7 @@ Object {
"schedule": Array [
"before 8am",
],
"semanticCommits": "enabled",
"semanticCommits": true,
"separateMajorMinor": true,
"separateMinorPatch": false,
"timezone": "Asia/Taipei",

View file

@ -510,11 +510,11 @@ export const presets: Record<string, Preset> = {
},
semanticCommits: {
description: 'Use semantic prefixes for commit messages and PR titles',
semanticCommits: 'enabled',
semanticCommits: true,
},
semanticCommitsDisabled: {
description: 'Disable semantic prefixes for commit messages and PR titles',
semanticCommits: 'disabled',
semanticCommits: false,
},
disableLockFiles: {
description: 'Disable lock file updates',

View file

@ -12,7 +12,7 @@ describe('workers/branch/automerge', () => {
...defaultConfig,
branchName: 'renovate/some-branch',
commitMessage: 'some commit message',
semanticCommits: 'disabled',
semanticCommits: false,
semanticCommitType: 'a',
semanticCommitScope: 'b',
updatedPackageFiles: [],

View file

@ -222,8 +222,7 @@ export async function getRepoConfig(
config.baseBranch = config.defaultBranch;
config = await checkOnboardingBranch(config);
config = await mergeRenovateConfig(config);
if (config.semanticCommits === 'auto') {
config.semanticCommits = await detectSemanticCommits();
}
config.semanticCommits =
config.semanticCommits ?? (await detectSemanticCommits());
return config;
}

View file

@ -17,13 +17,13 @@ describe('workers/repository/init/semantic', () => {
config.semanticCommits = null;
git.getCommitMessages.mockResolvedValue(['foo', 'bar']);
const res = await detectSemanticCommits();
expect(res).toBe('disabled');
expect(res).toBe(false);
});
it('detects true if known', async () => {
config.semanticCommits = null;
git.getCommitMessages.mockResolvedValue(['fix: foo', 'refactor: bar']);
const res = await detectSemanticCommits();
expect(res).toBe('enabled');
expect(res).toBe(true);
});
});
});

View file

@ -2,9 +2,7 @@ import conventionalCommitsDetector from 'conventional-commits-detector';
import { logger } from '../../../logger';
import { getCommitMessages } from '../../../util/git';
type DetectedSemanticCommit = 'enabled' | 'disabled';
export async function detectSemanticCommits(): Promise<DetectedSemanticCommit> {
export async function detectSemanticCommits(): Promise<boolean> {
logger.debug('detectSemanticCommits()');
const commitMessages = await getCommitMessages();
logger.trace(`commitMessages=${JSON.stringify(commitMessages)}`);
@ -12,8 +10,8 @@ export async function detectSemanticCommits(): Promise<DetectedSemanticCommit> {
logger.debug('Semantic commits detection: ' + type);
if (type === 'angular') {
logger.debug('angular semantic commits detected');
return 'enabled';
return true;
}
logger.debug('No semantic commits detected');
return 'disabled';
return false;
}

View file

@ -72,7 +72,7 @@ describe('workers/repository/onboarding/branch', () => {
describe('applies semanticCommit prefix', () => {
it('to the default commit message', async () => {
const prefix = 'chore(deps)';
config.semanticCommits = 'enabled';
config.semanticCommits = true;
await createOnboardingBranch(config);
expect(commitFiles).toHaveBeenCalledWith(
buildExpectedCommitFilesArgument(
@ -84,7 +84,7 @@ describe('workers/repository/onboarding/branch', () => {
const prefix = 'chore(deps)';
const message =
'I say, we can update when we want to, a commit they will never mind';
config.semanticCommits = 'enabled';
config.semanticCommits = true;
config.onboardingCommitMessage = message;
await createOnboardingBranch(config);
expect(commitFiles).toHaveBeenCalledWith(

View file

@ -17,7 +17,7 @@ export function createOnboardingBranch(
let commitMessagePrefix = '';
if (config.commitMessagePrefix) {
commitMessagePrefix = config.commitMessagePrefix;
} else if (config.semanticCommits === 'enabled') {
} else if (config.semanticCommits) {
commitMessagePrefix = config.semanticCommitType;
if (config.semanticCommitScope) {
commitMessagePrefix += `(${config.semanticCommitScope})`;

View file

@ -14,7 +14,7 @@ const defaultConfigFile = configFileNames[0];
function getCommitMessage(config: RenovateConfig): string {
let commitMessage: string;
// istanbul ignore if
if (config.semanticCommits === 'enabled') {
if (config.semanticCommits) {
commitMessage = config.semanticCommitType;
if (config.semanticCommitScope) {
commitMessage += `(${config.semanticCommitScope})`;

View file

@ -219,7 +219,7 @@ describe('workers/repository/updates/generate', () => {
partial<BranchUpgradeConfig>({
...defaultConfig,
depName: 'some-dep',
semanticCommits: 'enabled',
semanticCommits: true,
semanticCommitType: 'chore',
semanticCommitScope: 'package',
newValue: '1.2.0',
@ -243,7 +243,7 @@ describe('workers/repository/updates/generate', () => {
depName: 'some-dep',
packageFile: 'package.json',
baseDir: '',
semanticCommits: 'enabled',
semanticCommits: true,
semanticCommitType: 'chore',
semanticCommitScope: '{{baseDir}}',
newValue: '1.2.0',
@ -268,7 +268,7 @@ describe('workers/repository/updates/generate', () => {
depName: 'some-dep',
packageFile: 'foo/bar/package.json',
parentDir: 'bar',
semanticCommits: 'enabled',
semanticCommits: true,
semanticCommitType: 'chore',
semanticCommitScope: '{{parentDir}}',
newValue: '1.2.0',
@ -292,7 +292,7 @@ describe('workers/repository/updates/generate', () => {
depName: 'some-dep',
packageFile: 'foo/bar/package.json',
baseDir: 'foo/bar',
semanticCommits: 'enabled',
semanticCommits: true,
semanticCommitType: 'chore',
semanticCommitScope: '{{baseDir}}',
newValue: '1.2.0',

View file

@ -173,7 +173,7 @@ export function generateBranchConfig(
upgrade.isRange = false;
}
// Use templates to generate strings
if (upgrade.semanticCommits === 'enabled' && !upgrade.commitMessagePrefix) {
if (upgrade.semanticCommits && !upgrade.commitMessagePrefix) {
logger.trace('Upgrade has semantic commits enabled');
let semanticPrefix = upgrade.semanticCommitType;
if (upgrade.semanticCommitScope) {