- add logic which cleans up custom placeholders with the [] syntax which were not matched

This commit is contained in:
Mike Penz
2022-07-29 16:40:39 +00:00
committed by GitHub
parent fba9cdb51d
commit 74dd88f60c
4 changed files with 26 additions and 2 deletions
+14
View File
@@ -255,6 +255,7 @@ export function buildChangelog(diffInfo: DiffInfo, prs: PullRequestInfo[], optio
let transformedChangelog = config.template || DefaultConfiguration.template
transformedChangelog = replacePlaceholders(transformedChangelog, placeholderMap, placeholders, placeholderPrMap)
transformedChangelog = replacePrPlaceholders(transformedChangelog, placeholderPrMap)
transformedChangelog = cleanupPrPlaceHolders(transformedChangelog, placeholders)
core.info(`️ Filled template`)
return transformedChangelog
}
@@ -361,6 +362,19 @@ function replacePrPlaceholders(
return transformed
}
function cleanupPrPlaceHolders(
template: string,
placeholders: Map<string, Placeholder[]> /* placeholders to apply */
): string {
let transformed = template
for (const [, phs] of placeholders) {
for (const ph of phs) {
transformed = transformed.replaceAll(new RegExp(`\\$\\{\\{${ph.name}\\[.+?\\]\\}\\}`, 'gu'), '')
}
}
return transformed
}
function transform(filled: string, transformers: RegexTransformer[]): string {
if (transformers.length === 0) {
return filled