feat(templating): Implemented split_regex, replace_regex, find_regex filters#1287
Merged
orhun merged 4 commits intoorhun:mainfrom Nov 4, 2025
Merged
feat(templating): Implemented split_regex, replace_regex, find_regex filters#1287orhun merged 4 commits intoorhun:mainfrom
orhun merged 4 commits intoorhun:mainfrom
Conversation
|
Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️ |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1287 +/- ##
==========================================
+ Coverage 43.46% 44.18% +0.72%
==========================================
Files 22 22
Lines 1972 2008 +36
==========================================
+ Hits 857 887 +30
- Misses 1115 1121 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Collaborator
Contributor
Author
|
@orhun Super good point, would be rather confusing to use otherwise. |
Owner
|
Sorry I messed up the patch while sending it. Can you update the examples as follows: ## Custom built-in filters
**git-cliff** provides a few custom filters you can use inside templates:
- `upper_first`: Converts the first character of a string to uppercase.
```jinja
{{ "hello" | upper_first }} → Hello
```
- `find_regex`: Finds all occurrences of a regex pattern in a string.
```jinja
{{ "hello world, hello universe" | find_regex(pat="hello") }} → [hello, hello]
```
- `replace_regex`: Replaces all occurrences of a regex pattern with a string.
```jinja
{{ "hello world" | replace_regex(from="o", to="a") }} → hella warld
```
- `split_regex`: Splits a string by a regex pattern.
```jinja
{{ "hello world, hello universe" | split_regex(pat=" ") }} → [hello, world,, hello, universe]
``` |
Contributor
Author
|
@orhun Fixed! |
|
Congrats on merging your first pull request! ⛰️ |
1 task
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Motivation and Context
I was making use of git-cliff for a project that was using a bit more unorthodox commit style with message and body that requires me to be able to do some more advanced parsing when I generate changelogs.
How Has This Been Tested?
I wrote new test cases in
template.rsbut I have also run this on my own project changelogs on a project and successfully pulled all string sequences I was looking for out of the commit message to be able to process them in a way that I had to.I mainly needed the
find_regexfunction the split and replace is a bonus that came from testing different approaches.The project i work on use Azure DevOps and we add a user story, task or such number to the Pull Request when we create them, there can be multiple ones as well, and since it sadly doesn't use conventional commits we ended up using the user story number as a group.
But sometimes a PR includes multiple user stories and then we want to pull all of those from the message with a regex as such
(#\\d+)and then just write them all before the actual commit message that is included for a better overview.So we could write a really simple template like this
Screenshots / Logs (if applicable)
Types of Changes
Checklist: