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

feat(util/template): add prettyVersion field #16831

Merged
merged 38 commits into from Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f0d2c23
initial
hasanwhitesource Jul 25, 2022
49c84e7
expose prettyNewVersion and prettyNewMajor
hasanwhitesource Jul 27, 2022
a1f00e4
tests
hasanwhitesource Jul 27, 2022
02c3ba8
revert change
hasanwhitesource Jul 27, 2022
95f3aa2
simplify
hasanwhitesource Jul 27, 2022
a52ee6e
test naming
hasanwhitesource Jul 27, 2022
78e5414
documentation
hasanwhitesource Jul 27, 2022
d072e9f
documentation
hasanwhitesource Jul 28, 2022
14989c9
remove wrong documentation
hasanwhitesource Jul 28, 2022
ac97a7a
expose template finction
hasanwhitesource Jul 28, 2022
116dc5a
tests naming
hasanwhitesource Jul 28, 2022
619ea99
combine condition
hasanwhitesource Jul 28, 2022
805405a
Update docs/usage/templates.md
hasanwhitesource Jul 28, 2022
c990141
remove unecessary nullish op
hasanwhitesource Jul 28, 2022
2efbe76
Merge branch 'fix-v-in-version' of https://github.com/hasanwhitesourc…
hasanwhitesource Jul 28, 2022
70aa88b
Update docs/usage/templates.md
hasanwhitesource Jul 29, 2022
cfc5164
Merge branch 'main' into fix-v-in-version
hasanwhitesource Jul 29, 2022
9c3578f
Expose prettyVersion and prettyMajor
hasanwhitesource Aug 1, 2022
7fdca46
Merge branch 'fix-v-in-version' of https://github.com/hasanwhitesourc…
hasanwhitesource Aug 1, 2022
9d70c7b
documentation
hasanwhitesource Aug 1, 2022
de34859
Merge branch 'main' into fix-v-in-version
hasanwhitesource Aug 1, 2022
701fcb3
remove function and use regex
hasanwhitesource Aug 2, 2022
efb74b6
Merge branch 'fix-v-in-version' of https://github.com/hasanwhitesourc…
hasanwhitesource Aug 2, 2022
297a202
lexographic order
hasanwhitesource Aug 2, 2022
8d160ed
tests need fixing
hasanwhitesource Aug 3, 2022
f41d87c
Merge branch 'main' of https://github.com/renovatebot/renovate into f…
hasanwhitesource Aug 4, 2022
e2ded3b
add tests
hasanwhitesource Aug 4, 2022
77edbe8
Captial letter
hasanwhitesource Aug 4, 2022
a1d6ab6
renaming and prettyNewMajor
hasanwhitesource Aug 5, 2022
d2c21b9
space
hasanwhitesource Aug 5, 2022
ca2fbf8
move to upgrade interface
hasanwhitesource Aug 5, 2022
8ca03fb
Merge branch 'main' into fix-v-in-version
rarkins Aug 6, 2022
ae03414
use new fields where v is prepended manually
hasanwhitesource Aug 6, 2022
19c0339
Merge branch 'main' into fix-v-in-version
rarkins Aug 6, 2022
17273bb
Merge branch 'main' into fix-v-in-version
rarkins Aug 7, 2022
5b17d1a
Merge branch 'main' into fix-v-in-version
rarkins Aug 8, 2022
5acb2a4
move to interface
hasanwhitesource Aug 8, 2022
4d7d84a
Merge branch 'main' into fix-v-in-version
viceice Aug 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions docs/usage/configuration-options.md
Expand Up @@ -2138,6 +2138,22 @@ Here's an example of how you would define PR priority so that devDependencies ar

The PR title is important for some of Renovate's matching algorithms (e.g. determining whether to recreate a PR or not) so ideally don't modify it much.

## prettyNewMajor

This option allows editing `newMajor` value by templating, it is defaulted to prepend `v` to the `newMajor` value.

For example, to create a PR title with the changed version:

`{ "commitMessageExtra": "{{prettyNewMajor}}" }`

## prettyVersion
hasanwhitesource marked this conversation as resolved.
Show resolved Hide resolved

This option allows editing `newVersion` value by templating, it is defaulted to prepend `v` to the `newVersion` value.

For example, to create a PR title with the changed version:

`{ "commitMessageExtra": "{{prettyNewVersion}}" }`

## printConfig

This option is useful for troubleshooting, particularly if using presets.
Expand Down
7 changes: 7 additions & 0 deletions docs/usage/templates.md
Expand Up @@ -83,3 +83,10 @@ In the example above, it will only show a text if `isMajor=true` and `hasRelease
Returns `true` if at least one expression is `true`.

`{{#if (or isPatch isSingleVersion}}Small update, safer to merge and release.{{else}}Check out the changelog for all versions before merging!{{/if}}`

## prettifyVersion

Prepends `v` to start of `newMajor` or `newVersion` or any string not starting with `v`.
For example, to create a PR title with the changed version:

`{ "commitMessageExtra": "{{prettifyVersion newVersion}}" }`
14 changes: 14 additions & 0 deletions lib/config/options/index.ts
Expand Up @@ -1633,6 +1633,20 @@ const options: RenovateOptions[] = [
default: 'dependency {{depName}}',
cli: false,
},
{
name: 'prettyVersion',
description: 'the new version value with v prepended to it.',
type: 'string',
default: '{{prettifyVersion newVersion}}',
cli: false,
},
{
name: 'prettyNewMajor',
description: 'The new major value with v prepended to it',
type: 'string',
default: '{{prettifyVersion newMajor}}',
cli: false,
},
hasanwhitesource marked this conversation as resolved.
Show resolved Hide resolved
{
name: 'commitMessageExtra',
description:
Expand Down
21 changes: 21 additions & 0 deletions lib/util/template/index.spec.ts
Expand Up @@ -80,4 +80,25 @@ describe('util/template/index', () => {
const output = template.compile(userTemplate, undefined as never);
expect(output).toBe('foo');
});

it('does not append v to version when present', () => {
const userTemplate = '{{{prettifyVersion newVersion}}}';
const input = { newVersion: 'v5.1.2' };
const output = template.compile(userTemplate, input);
expect(output).toBe('v5.1.2');
});

it('appends v to version when present', () => {
const userTemplate = '{{{prettifyVersion newVersion}}}';
const input = { newVersion: '5.1.2' };
const output = template.compile(userTemplate, input);
expect(output).toBe('v5.1.2');
});

it('appends v to newMajor', () => {
const userTemplate = '{{{prettifyVersion newMajor}}}';
const input = { newMajor: 5 };
const output = template.compile(userTemplate, input);
expect(output).toBe('v5');
});
});
9 changes: 9 additions & 0 deletions lib/util/template/index.ts
Expand Up @@ -23,6 +23,13 @@ handlebars.registerHelper('containsString', (str, subStr) =>
str?.includes(subStr)
);

handlebars.registerHelper('prettifyVersion', (version: string | number) => {
if (is.string(version) && version.charAt(0) === 'v') {
return version;
}
return `v${version}`;
});

handlebars.registerHelper({
and(...args) {
// Need to remove the 'options', as last parameter
Expand Down Expand Up @@ -59,6 +66,8 @@ export const exposedConfigOptions = [
'prBodyDefinitions',
'prBodyNotes',
'prTitle',
'prettyVersion',
'prettyNewMajor',
'semanticCommitScope',
'semanticCommitType',
'separateMajorMinor',
Expand Down
44 changes: 44 additions & 0 deletions lib/workers/repository/updates/generate.spec.ts
Expand Up @@ -564,6 +564,50 @@ describe('workers/repository/updates/generate', () => {
);
});

it('use pretty new version in 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}}',
commitMessageExtra: '{{prettyVersion}}',
newValue: '1.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 pretty new major in 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}}',
commitMessageExtra: '{{prettyNewMajor}}',
newValue: '3.2.0',
newVersion: 'v3.2.0',
newMajor: 3,
} as BranchUpgradeConfig,
];
const res = generateBranchConfig(branch);
expect(res.prTitle).toBe('chore(foo/bar): update dependency some-dep v3');
});

it('adds commit message body', () => {
// TODO #7154 incompatible types
const branch: BranchUpgradeConfig[] = [
Expand Down