diff --git a/__tests__/transform.test.ts b/__tests__/transform.test.ts index 4de9f85..5684d7c 100644 --- a/__tests__/transform.test.ts +++ b/__tests__/transform.test.ts @@ -597,11 +597,19 @@ it('Extract custom placeholder from PR body and replace in global template', asy pattern: '.+ b(....).+', target: '\n- $1' } + }, + { + name: 'C_PLACEHOLER_3', + source: 'BODY', + transformer: { + pattern: '.+(body1).+', + target: '$1' + } } ] customConfig.template = '${{CHANGELOG}}\n\n${{C_PLACEHOLER_2[2]}}\n\n${{C_PLACEHOLER_2[*]}}${{C_PLACEHOLDER_1[7]}}${{C_PLACEHOLER_2[1493]}}' - customConfig.pr_template = '${{BODY}} ----> ${{C_PLACEHOLDER_1}}' + customConfig.pr_template = '${{BODY}} ----> ${{C_PLACEHOLDER_1}}${{C_PLACEHOLER_3}}' const resultChangelog = buildChangelog(DefaultDiffInfo, mergedPullRequests, { owner: 'mikepenz', @@ -617,6 +625,6 @@ it('Extract custom placeholder from PR body and replace in global template', asy }) expect(resultChangelog).toStrictEqual( - `## ๐Ÿš€ Features\n\nno magic body1 for this matter ----> - body1\nno magic body3 for this matter ----> - body3\n\n## ๐Ÿ› Fixes\n\nno magic body2 for this matter ----> - body2\nno magic body3 for this matter ----> - body3\n\n## ๐Ÿงช Others\n\nno magic body4 for this matter ----> - body4\n\n\n\n\n- ody3\n\n\n- ody1\n- ody2\n- ody3\n- ody4` + `## ๐Ÿš€ Features\n\nno magic body1 for this matter ----> - body1body1\nno magic body3 for this matter ----> - body3\n\n## ๐Ÿ› Fixes\n\nno magic body2 for this matter ----> - body2\nno magic body3 for this matter ----> - body3\n\n## ๐Ÿงช Others\n\nno magic body4 for this matter ----> - body4\n\n\n\n\n- ody3\n\n\n- ody1\n- ody2\n- ody3\n- ody4` ) }) diff --git a/src/transform.ts b/src/transform.ts index 3d3ee50..7fba0e0 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -379,7 +379,7 @@ function cleanupPrPlaceHolders( let transformed = template for (const [, phs] of placeholders) { for (const ph of phs) { - transformed = transformed.replaceAll(new RegExp(`\\$\\{\\{${ph.name}\\[.+?\\]\\}\\}`, 'gu'), '') + transformed = transformed.replaceAll(new RegExp(`\\$\\{\\{${ph.name}(?:\\[.+?\\])?\\}\\}`, 'gu'), '') } } return transformed