mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-11 06:26:26 +00:00
fix: Revert "fix: commit message" (#16263)
Revert "fix: commit message (#16239)"
This reverts commit 3b0c2afe8a
.
This commit is contained in:
parent
a1344d86ac
commit
787c98cdbe
4 changed files with 32 additions and 68 deletions
|
@ -60,10 +60,6 @@ export abstract class CommitMessage {
|
||||||
this._footer = this.normalizeInput(value);
|
this._footer = this.normalizeInput(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
get subject(): string {
|
|
||||||
return this._subject;
|
|
||||||
}
|
|
||||||
|
|
||||||
set subject(value: string) {
|
set subject(value: string) {
|
||||||
this._subject = this.normalizeInput(value);
|
this._subject = this.normalizeInput(value);
|
||||||
this._subject = this._subject?.replace(
|
this._subject = this._subject?.replace(
|
||||||
|
|
|
@ -25,15 +25,6 @@ describe('workers/repository/model/semantic-commit-message', () => {
|
||||||
expect(message.toString()).toBe('fix(scope): test');
|
expect(message.toString()).toBe('fix(scope): test');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should transform to lowercase only first letter', () => {
|
|
||||||
const message = new SemanticCommitMessage();
|
|
||||||
message.subject = 'Update My Org dependencies';
|
|
||||||
message.type = 'fix';
|
|
||||||
message.scope = 'deps ';
|
|
||||||
|
|
||||||
expect(message.toString()).toBe('fix(deps): update My Org dependencies');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should create instance from string without scope', () => {
|
it('should create instance from string without scope', () => {
|
||||||
const instance = SemanticCommitMessage.fromString('feat: ticket 123');
|
const instance = SemanticCommitMessage.fromString('feat: ticket 123');
|
||||||
|
|
||||||
|
|
|
@ -506,7 +506,7 @@ describe('workers/repository/updates/generate', () => {
|
||||||
} as BranchUpgradeConfig,
|
} as BranchUpgradeConfig,
|
||||||
];
|
];
|
||||||
const res = generateBranchConfig(branch);
|
const res = generateBranchConfig(branch);
|
||||||
expect(res.prTitle).toBe('chore: update dependency some-dep to v1.2.0');
|
expect(res.prTitle).toBe('chore(): update dependency some-dep to v1.2.0');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('scopes monorepo commits with nested package files using parent directory', () => {
|
it('scopes monorepo commits with nested package files using parent directory', () => {
|
||||||
|
@ -915,37 +915,5 @@ describe('workers/repository/updates/generate', () => {
|
||||||
'`1.1.1` (+1)',
|
'`1.1.1` (+1)',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fixes commit message with body', () => {
|
|
||||||
const branch: BranchUpgradeConfig[] = [
|
|
||||||
{
|
|
||||||
manager: 'some-manager',
|
|
||||||
branchName: 'some-branch',
|
|
||||||
commitMessage: 'update to vv1.2.0',
|
|
||||||
commitBody: 'some body',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
const res = generateBranchConfig(branch);
|
|
||||||
expect(res.commitMessage).toBe('Update to v1.2.0\n\nsome body');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('generates semantic commit message properly', () => {
|
|
||||||
const branch: BranchUpgradeConfig[] = [
|
|
||||||
{
|
|
||||||
...defaultConfig,
|
|
||||||
manager: 'some-manager',
|
|
||||||
branchName: 'some-branch',
|
|
||||||
semanticCommits: 'enabled',
|
|
||||||
semanticCommitType: 'chore',
|
|
||||||
semanticCommitScope: 'deps',
|
|
||||||
depName: 'some-dep',
|
|
||||||
newValue: '1.2.0',
|
|
||||||
} as BranchUpgradeConfig,
|
|
||||||
];
|
|
||||||
const res = generateBranchConfig(branch);
|
|
||||||
expect(res.commitMessage).toBe(
|
|
||||||
'chore(deps): update dependency some-dep to 1.2.0'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,12 +6,11 @@ import semver from 'semver';
|
||||||
import { mergeChildConfig } from '../../../config';
|
import { mergeChildConfig } from '../../../config';
|
||||||
import { CONFIG_SECRETS_EXPOSED } from '../../../constants/error-messages';
|
import { CONFIG_SECRETS_EXPOSED } from '../../../constants/error-messages';
|
||||||
import { logger } from '../../../logger';
|
import { logger } from '../../../logger';
|
||||||
import { regEx } from '../../../util/regex';
|
import { newlineRegex, regEx } from '../../../util/regex';
|
||||||
import { sanitize } from '../../../util/sanitize';
|
import { sanitize } from '../../../util/sanitize';
|
||||||
import * as template from '../../../util/template';
|
import * as template from '../../../util/template';
|
||||||
import type { BranchConfig, BranchUpgradeConfig } from '../../types';
|
import type { BranchConfig, BranchUpgradeConfig } from '../../types';
|
||||||
import { CommitMessageFactory } from '../model/commit-message-factory';
|
import { CommitMessage } from '../model/commit-message';
|
||||||
import { SemanticCommitMessage } from '../model/semantic-commit-message';
|
|
||||||
|
|
||||||
function isTypesGroup(branchUpgrades: BranchUpgradeConfig[]): boolean {
|
function isTypesGroup(branchUpgrades: BranchUpgradeConfig[]): boolean {
|
||||||
return (
|
return (
|
||||||
|
@ -168,27 +167,28 @@ export function generateBranchConfig(
|
||||||
} else if (semver.valid(toVersions[0])) {
|
} else if (semver.valid(toVersions[0])) {
|
||||||
upgrade.isRange = false;
|
upgrade.isRange = false;
|
||||||
}
|
}
|
||||||
const commitMessageFactory = new CommitMessageFactory(upgrade);
|
|
||||||
const commitMessage = commitMessageFactory.create();
|
|
||||||
// Use templates to generate strings
|
// Use templates to generate strings
|
||||||
if (
|
if (upgrade.semanticCommits === 'enabled' && !upgrade.commitMessagePrefix) {
|
||||||
SemanticCommitMessage.is(commitMessage) &&
|
|
||||||
upgrade.semanticCommitScope
|
|
||||||
) {
|
|
||||||
logger.trace('Upgrade has semantic commits enabled');
|
logger.trace('Upgrade has semantic commits enabled');
|
||||||
commitMessage.scope = template.compile(
|
let semanticPrefix = upgrade.semanticCommitType;
|
||||||
|
if (upgrade.semanticCommitScope) {
|
||||||
|
semanticPrefix += `(${template.compile(
|
||||||
upgrade.semanticCommitScope,
|
upgrade.semanticCommitScope,
|
||||||
upgrade
|
upgrade
|
||||||
);
|
)})`;
|
||||||
|
}
|
||||||
|
upgrade.commitMessagePrefix = CommitMessage.formatPrefix(semanticPrefix!);
|
||||||
|
upgrade.toLowerCase =
|
||||||
|
regEx(/[A-Z]/).exec(upgrade.semanticCommitType!) === null &&
|
||||||
|
!upgrade.semanticCommitType!.startsWith(':');
|
||||||
}
|
}
|
||||||
// Compile a few times in case there are nested templates
|
// Compile a few times in case there are nested templates
|
||||||
commitMessage.subject = template.compile(
|
upgrade.commitMessage = template.compile(
|
||||||
upgrade.commitMessage ?? '',
|
upgrade.commitMessage ?? '',
|
||||||
upgrade
|
upgrade
|
||||||
);
|
);
|
||||||
commitMessage.subject = template.compile(commitMessage.subject, upgrade);
|
upgrade.commitMessage = template.compile(upgrade.commitMessage, upgrade);
|
||||||
commitMessage.subject = template.compile(commitMessage.subject, upgrade);
|
upgrade.commitMessage = template.compile(upgrade.commitMessage, upgrade);
|
||||||
upgrade.commitMessage = commitMessage.toString();
|
|
||||||
// istanbul ignore if
|
// istanbul ignore if
|
||||||
if (upgrade.commitMessage !== sanitize(upgrade.commitMessage)) {
|
if (upgrade.commitMessage !== sanitize(upgrade.commitMessage)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -197,14 +197,23 @@ export function generateBranchConfig(
|
||||||
);
|
);
|
||||||
throw new Error(CONFIG_SECRETS_EXPOSED);
|
throw new Error(CONFIG_SECRETS_EXPOSED);
|
||||||
}
|
}
|
||||||
commitMessage.subject = commitMessage.subject.replace(
|
upgrade.commitMessage = upgrade.commitMessage.trim(); // Trim exterior whitespace
|
||||||
|
upgrade.commitMessage = upgrade.commitMessage.replace(regEx(/\s+/g), ' '); // Trim extra whitespace inside string
|
||||||
|
upgrade.commitMessage = upgrade.commitMessage.replace(
|
||||||
regEx(/to vv(\d)/),
|
regEx(/to vv(\d)/),
|
||||||
'to v$1'
|
'to v$1'
|
||||||
);
|
);
|
||||||
upgrade.commitMessage = commitMessage.toString();
|
if (upgrade.toLowerCase) {
|
||||||
|
// We only need to lowercase the first line
|
||||||
|
const splitMessage = upgrade.commitMessage.split(newlineRegex);
|
||||||
|
splitMessage[0] = splitMessage[0].toLowerCase();
|
||||||
|
upgrade.commitMessage = splitMessage.join('\n');
|
||||||
|
}
|
||||||
if (upgrade.commitBody) {
|
if (upgrade.commitBody) {
|
||||||
commitMessage.body = template.compile(upgrade.commitBody, upgrade);
|
upgrade.commitMessage = `${upgrade.commitMessage}\n\n${template.compile(
|
||||||
upgrade.commitMessage = commitMessage.toString();
|
upgrade.commitBody,
|
||||||
|
upgrade
|
||||||
|
)}`;
|
||||||
}
|
}
|
||||||
logger.trace(`commitMessage: ` + JSON.stringify(upgrade.commitMessage));
|
logger.trace(`commitMessage: ` + JSON.stringify(upgrade.commitMessage));
|
||||||
if (upgrade.prTitle) {
|
if (upgrade.prTitle) {
|
||||||
|
@ -226,7 +235,7 @@ export function generateBranchConfig(
|
||||||
upgrade.prTitle = upgrade.prTitle.toLowerCase();
|
upgrade.prTitle = upgrade.prTitle.toLowerCase();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
upgrade.prTitle = commitMessage.title;
|
[upgrade.prTitle] = upgrade.commitMessage.split(newlineRegex);
|
||||||
}
|
}
|
||||||
upgrade.prTitle += upgrade.hasBaseBranches ? ' ({{baseBranch}})' : '';
|
upgrade.prTitle += upgrade.hasBaseBranches ? ' ({{baseBranch}})' : '';
|
||||||
if (upgrade.isGroup) {
|
if (upgrade.isGroup) {
|
||||||
|
|
Loading…
Reference in a new issue