diff --git a/lib/config/options/index.ts b/lib/config/options/index.ts index b2bd8c206a2bddc5c3203c9b5b39947ac90eca8a..4a0439c8530f3ff9b2ff0d87a3d9673f94af02c8 100644 --- a/lib/config/options/index.ts +++ b/lib/config/options/index.ts @@ -1358,7 +1358,7 @@ const options: RenovateOptions[] = [ branchTopic: '{{{depNameSanitized}}}-replacement', commitMessageAction: 'Replace', commitMessageExtra: - 'with {{newName}} {{#if isMajor}}v{{{newMajor}}}{{else}}{{#if isSingleVersion}}v{{{newVersion}}}{{else}}{{{newValue}}}{{/if}}{{/if}}', + 'with {{newName}} {{#if isMajor}}{{{prettyNewMajor}}}{{else}}{{#if isSingleVersion}}{{{prettyNewVersion}}}{{else}}{{{newValue}}}{{/if}}{{/if}}', prBodyNotes: [ 'This is a special PR that replaces `{{{depNameSanitized}}}` with the community suggested minimal stable replacement version.', ], @@ -1639,7 +1639,7 @@ const options: RenovateOptions[] = [ 'Extra description used after the commit message topic - typically the version.', type: 'string', default: - 'to {{#if isPinDigest}}{{{newDigestShort}}}{{else}}{{#if isMajor}}v{{{newMajor}}}{{else}}{{#if isSingleVersion}}v{{{newVersion}}}{{else}}{{#if newValue}}{{{newValue}}}{{else}}{{{newDigestShort}}}{{/if}}{{/if}}{{/if}}{{/if}}', + 'to {{#if isPinDigest}}{{{newDigestShort}}}{{else}}{{#if isMajor}}{{prettyNewMajor}}{{else}}{{#if isSingleVersion}}{{prettyNewVersion}}{{else}}{{#if newValue}}{{{newValue}}}{{else}}{{{newDigestShort}}}{{/if}}{{/if}}{{/if}}{{/if}}', cli: false, }, { diff --git a/lib/modules/datasource/docker/index.ts b/lib/modules/datasource/docker/index.ts index 3d02ed28561ed6219f2c5e1cdade909e2b4ddd46..82645d7a6c2d19e12f3bfd9bc7ea6e90199401c0 100644 --- a/lib/modules/datasource/docker/index.ts +++ b/lib/modules/datasource/docker/index.ts @@ -338,7 +338,7 @@ export function isECRMaxResultsError(err: HttpError): boolean { export const defaultConfig = { commitMessageTopic: '{{{depName}}} Docker tag', commitMessageExtra: - 'to v{{#if isMajor}}{{{newMajor}}}{{else}}{{{newVersion}}}{{/if}}', + 'to {{#if isMajor}}{{{prettyNewMajor}}}{{else}}{{{prettyNewVersion}}}{{/if}}', digest: { branchTopic: '{{{depNameSanitized}}}-{{{currentValue}}}', commitMessageExtra: 'to {{newDigestShort}}', diff --git a/lib/modules/manager/buildkite/index.ts b/lib/modules/manager/buildkite/index.ts index 028d54c729708dc59721a746ea620f198f5d8c56..d50a6e18b8d0c13cbddda6cb2d53050dfb40dc63 100644 --- a/lib/modules/manager/buildkite/index.ts +++ b/lib/modules/manager/buildkite/index.ts @@ -7,7 +7,7 @@ export const defaultConfig = { fileMatch: ['buildkite\\.ya?ml', '\\.buildkite/.+\\.ya?ml$'], commitMessageTopic: 'buildkite plugin {{depName}}', commitMessageExtra: - 'to {{#if isMajor}}v{{{newMajor}}}{{else}}{{{newValue}}}{{/if}}', + 'to {{#if isMajor}}{{{prettyNewMajor}}}{{else}}{{{newValue}}}{{/if}}', }; export const supportedDatasources = [GithubTagsDatasource.id]; diff --git a/lib/util/template/index.ts b/lib/util/template/index.ts index 6fedb3617249dd654a6b5458ad83a390d2767179..f6dfd30ae6b7fd4a37be6c5b0fd5fac1397d8cd1 100644 --- a/lib/util/template/index.ts +++ b/lib/util/template/index.ts @@ -117,6 +117,8 @@ export const allowedFields = { 'The name of the directory that the dependency was found in, without full path', platform: 'VCS platform in use, e.g. "github", "gitlab", etc.', prettyDepType: 'Massaged depType', + prettyNewMajor: 'The new major value with v prepended to it.', + prettyNewVersion: 'The new version value with v prepended to it.', project: 'ChangeLogProject object', recreateClosed: 'If true, this PR will be recreated if closed', references: 'A list of references for the upgrade', diff --git a/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap b/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap index eb890680e9d6bd0e9276d6a08eda3b3e54feb0fd..59e1f8cdc8893f7ad2bb85a5ad77d9a1f506239b 100644 --- a/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap +++ b/lib/workers/repository/updates/__snapshots__/generate.spec.ts.snap @@ -156,6 +156,7 @@ Object { "newVersion": "0.5.8", "prTitle": "some-title", "prettyDepType": "dependency", + "prettyNewVersion": "v0.5.8", }, ], } @@ -221,6 +222,7 @@ Object { "prBodyColumns": Array [], "prTitle": "some-title", "prettyDepType": "dependency", + "prettyNewVersion": "v1.0.1", "releaseTimestamp": undefined, "reuseLockFiles": true, "upgrades": Array [ @@ -240,6 +242,7 @@ Object { "newVersion": "1.0.1", "prTitle": "some-title", "prettyDepType": "dependency", + "prettyNewVersion": "v1.0.1", }, ], } diff --git a/lib/workers/repository/updates/generate.spec.ts b/lib/workers/repository/updates/generate.spec.ts index fdab3f042d1844b10237597d71dcd8c2b9fc8e73..de9aae117a8d9b6815a1b69f265fcae213d501bb 100644 --- a/lib/workers/repository/updates/generate.spec.ts +++ b/lib/workers/repository/updates/generate.spec.ts @@ -80,6 +80,7 @@ describe('workers/repository/updates/generate', () => { newValue: '^1.0.0', newVersion: '1.0.1', reuseLockFiles: true, + prettyNewVersion: 'v1.0.1', upgrades: [ { branchName: 'some-branch', @@ -90,6 +91,7 @@ describe('workers/repository/updates/generate', () => { lockedVersion: '1.0.0', newValue: '^1.0.0', newVersion: '1.0.1', + prettyNewVersion: 'v1.0.1', }, ], }); @@ -134,7 +136,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '5.1.2', newVersion: '5.1.2', @@ -154,7 +156,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '5.1.2', newVersion: '5.1.2', @@ -175,7 +177,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '5.1.2', newVersion: '5.1.2', @@ -206,7 +208,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '5.1.2', newVersion: '5.1.2', @@ -220,7 +222,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '5.2.0', newVersion: '5.2.0', @@ -242,7 +244,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '5.1.2', newVersion: '5.1.2', @@ -258,7 +260,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '1.1.0', newVersion: '1.1.0', @@ -285,7 +287,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '^6.0', newVersion: '6.0.3', @@ -301,7 +303,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '^6.0', newVersion: '6.0.1', @@ -328,7 +330,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '^6.0.1', newVersion: '6.0.2', @@ -344,7 +346,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '^6.0.0', newVersion: '6.0.2', @@ -371,7 +373,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', isDigest: true, currentDigest: 'abcdefghijklmnopqrstuvwxyz', newDigest: '123abcdefghijklmnopqrstuvwxyz', @@ -387,7 +389,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: 'zzzzzzzzzz', group: { @@ -428,7 +430,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '>= 5.1.2', newVersion: '5.1.2', @@ -444,7 +446,7 @@ describe('workers/repository/updates/generate', () => { branchName: 'some-branch', prTitle: 'some-title', commitMessageExtra: - 'to {{#if isMajor}}v{{newMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', + 'to {{#if isMajor}}{{prettyNewMajor}}{{else}}{{#unless isRange}}v{{/unless}}{{newValue}}{{/if}}', foo: 1, newValue: '^5,1,2', newVersion: '5.1.2', @@ -564,6 +566,95 @@ describe('workers/repository/updates/generate', () => { ); }); + it('use prettyVersion in pr title when there is a v', () => { + const branch: BranchUpgradeConfig[] = [ + { + ...defaultConfig, + manager: 'some-manager', + depName: 'some-dep', + packageFile: 'foo/bar/package.json', + packageFileDir: 'foo/bar', + semanticCommits: 'enabled', + semanticCommitType: 'chore', + semanticCommitScope: '{{packageFileDir}}', + commitMessageExtra: '{{prettyNewVersion}}', + newValue: 'v1.2.0', + isSingleVersion: true, + newVersion: 'v1.2.0', + } as BranchUpgradeConfig, + ]; + const res = generateBranchConfig(branch); + expect(res.prTitle).toBe( + 'chore(foo/bar): update dependency some-dep v1.2.0' + ); + }); + + it('use prettyVersion in pr title there is no v', () => { + const branch: BranchUpgradeConfig[] = [ + { + ...defaultConfig, + manager: 'some-manager', + depName: 'some-dep', + packageFile: 'foo/bar/package.json', + packageFileDir: 'foo/bar', + semanticCommits: 'enabled', + semanticCommitType: 'chore', + semanticCommitScope: '{{packageFileDir}}', + commitMessageExtra: '{{prettyNewVersion}}', + newValue: '3.2.0', + newVersion: '3.2.0', + newMajor: 3, + } as BranchUpgradeConfig, + ]; + const res = generateBranchConfig(branch); + expect(res.prTitle).toBe( + 'chore(foo/bar): update dependency some-dep v3.2.0' + ); + }); + + it('use newMajor in pr title with v', () => { + const branch: BranchUpgradeConfig[] = [ + { + ...defaultConfig, + manager: 'some-manager', + depName: 'some-dep', + packageFile: 'foo/bar/package.json', + packageFileDir: 'foo/bar', + semanticCommits: 'enabled', + semanticCommitType: 'chore', + semanticCommitScope: '{{packageFileDir}}', + commitMessageExtra: '{{prettyNewMajor}}', + newValue: '3.2.0', + newVersion: '3.2.0', + newMajor: 3, + } as BranchUpgradeConfig, + ]; + const res = generateBranchConfig(branch); + expect(res.prTitle).toBe('chore(foo/bar): update dependency some-dep v3'); + }); + + it('Default commitMessageExtra pr title', () => { + const branch: BranchUpgradeConfig[] = [ + { + ...defaultConfig, + manager: 'some-manager', + depName: 'some-dep', + packageFile: 'foo/bar/package.json', + packageFileDir: 'foo/bar', + semanticCommits: 'enabled', + semanticCommitType: 'chore', + semanticCommitScope: '{{packageFileDir}}', + newValue: 'v1.2.0', + isSingleVersion: true, + newVersion: 'v1.2.0', + } as BranchUpgradeConfig, + ]; + const res = generateBranchConfig(branch); + expect(res.prTitle).toBe( + 'chore(foo/bar): update dependency some-dep to v1.2.0' + ); + }); + it('adds commit message body', () => { // TODO #7154 incompatible types const branch: BranchUpgradeConfig[] = [ diff --git a/lib/workers/repository/updates/generate.ts b/lib/workers/repository/updates/generate.ts index 2bbad40db574ed3b553cecf3574b799d2321d806..9ffec7ff5f641aefe26b45646d60fe36641785fe 100644 --- a/lib/workers/repository/updates/generate.ts +++ b/lib/workers/repository/updates/generate.ts @@ -182,6 +182,15 @@ export function generateBranchConfig( regEx(/[A-Z]/).exec(upgrade.semanticCommitType!) === null && !upgrade.semanticCommitType!.startsWith(':'); } + // prettify newVersion and newMajor for printing + if (upgrade.newVersion) { + upgrade.prettyNewVersion = upgrade.newVersion.startsWith('v') + ? upgrade.newVersion + : `v${upgrade.newVersion}`; + } + if (upgrade.newMajor) { + upgrade.prettyNewMajor = `v${upgrade.newMajor}`; + } // Compile a few times in case there are nested templates upgrade.commitMessage = template.compile( upgrade.commitMessage ?? '', diff --git a/lib/workers/types.ts b/lib/workers/types.ts index 1159400107b34e7502974e74733053aa1b4f9960..87f3cc36b9c7c8f8dfeab9b6c866504849bfa02c 100644 --- a/lib/workers/types.ts +++ b/lib/workers/types.ts @@ -57,6 +57,8 @@ export interface BranchUpgradeConfig prBodyTemplate?: string; prPriority?: number; prTitle?: string; + prettyNewMajor?: string; + prettyNewVersion?: string; releases?: ReleaseWithNotes[]; releaseTimestamp?: string; repoName?: string;