-
-
Notifications
You must be signed in to change notification settings - Fork 264
feat(templating): Implemented split_regex, replace_regex, find_regex filters #1287
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
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:
|
orhun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
@orhun Super good point, would be rather confusing to use otherwise. |
|
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]
``` |
|
@orhun Fixed! |
orhun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
|
Congrats on merging your first pull request! ⛰️ |
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: