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

Expand repeated placeholders in commit message #29

Merged
merged 1 commit into from Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
25 changes: 25 additions & 0 deletions src/main-test.ts
Expand Up @@ -16,13 +16,38 @@ test('commitForRelease()', (t) => {
}),
'chore(test formula): version {{version}}'
)
t.is(
commitForRelease('{formulaName} {version}', {
formulaName: 'test formula',
version: 'v1.2.3',
}),
'{formulaName} {version}'
)
t.is(
commitForRelease('chore({{formulaName}}): upgrade to version {{version}}', {
formulaName: 'test formula',
version: 'v1.2.3',
}),
'chore(test formula): upgrade to version v1.2.3'
)
t.is(
commitForRelease(
'{{formulaName}} {{version}}: upgrade {{formulaName}} to version {{version}}',
{
formulaName: 'test formula',
version: 'v1.2.3',
}
),
'test formula v1.2.3: upgrade test formula to version v1.2.3'
)
t.is(
commitForRelease('{{constructor}}{{__proto__}}', {}),
'{{constructor}}{{__proto__}}'
)
t.is(
commitForRelease('{{version}}', { version: 'v{{version}}' }),
'v{{version}}'
)
})

test('prepareEdit()', async (t) => {
Expand Down
11 changes: 8 additions & 3 deletions src/main.ts
Expand Up @@ -18,9 +18,14 @@ export function commitForRelease(
messageTemplate: string,
params: { [key: string]: string } = {}
): string {
return Object.keys(params).reduce(
(currentMessage, tag) => currentMessage.replace(`{{${tag}}}`, params[tag]),
messageTemplate
return messageTemplate.replace(
/\{\{(\w+)\}\}/g,
(m: string, key: string): string => {
if (params.hasOwnProperty(key)) {
return params[key]
}
return m
}
)
}

Expand Down