Skip to content

Commit

Permalink
feat(util/template): add prettyNewMajor and prettyNewVersion field (#…
Browse files Browse the repository at this point in the history
…16831)

* initial

* expose prettyNewVersion and prettyNewMajor

* tests

* revert change

* simplify

* test naming

* documentation

* documentation

* remove wrong documentation

* expose template finction

* tests naming

* combine condition

* Update docs/usage/templates.md

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>

* remove unecessary nullish op

* Update docs/usage/templates.md

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* Expose prettyVersion and prettyMajor

* documentation

* remove function and use regex

* lexographic order

* tests need fixing

* add tests

* Captial letter

* renaming and prettyNewMajor

* space

* move to upgrade interface

* use new fields where v is prepended manually

* move to interface

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
Co-authored-by: Rhys Arkins <rhys@arkins.net>
  • Loading branch information
4 people committed Aug 8, 2022
1 parent 1111b32 commit 4ead106
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 19 deletions.
4 changes: 2 additions & 2 deletions lib/config/options/index.ts
Expand Up @@ -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.',
],
Expand Down Expand Up @@ -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,
},
{
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/docker/index.ts
Expand Up @@ -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}}',
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/buildkite/index.ts
Expand Up @@ -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];
2 changes: 2 additions & 0 deletions lib/util/template/index.ts
Expand Up @@ -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',
Expand Down
Expand Up @@ -156,6 +156,7 @@ Object {
"newVersion": "0.5.8",
"prTitle": "some-title",
"prettyDepType": "dependency",
"prettyNewVersion": "v0.5.8",
},
],
}
Expand Down Expand Up @@ -221,6 +222,7 @@ Object {
"prBodyColumns": Array [],
"prTitle": "some-title",
"prettyDepType": "dependency",
"prettyNewVersion": "v1.0.1",
"releaseTimestamp": undefined,
"reuseLockFiles": true,
"upgrades": Array [
Expand All @@ -240,6 +242,7 @@ Object {
"newVersion": "1.0.1",
"prTitle": "some-title",
"prettyDepType": "dependency",
"prettyNewVersion": "v1.0.1",
},
],
}
Expand Down
121 changes: 106 additions & 15 deletions lib/workers/repository/updates/generate.spec.ts
Expand Up @@ -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',
Expand All @@ -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',
},
],
});
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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: {
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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[] = [
Expand Down
9 changes: 9 additions & 0 deletions lib/workers/repository/updates/generate.ts
Expand Up @@ -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 ?? '',
Expand Down
2 changes: 2 additions & 0 deletions lib/workers/types.ts
Expand Up @@ -57,6 +57,8 @@ export interface BranchUpgradeConfig
prBodyTemplate?: string;
prPriority?: number;
prTitle?: string;
prettyNewMajor?: string;
prettyNewVersion?: string;
releases?: ReleaseWithNotes[];
releaseTimestamp?: string;
repoName?: string;
Expand Down

0 comments on commit 4ead106

Please sign in to comment.