Skip to content

Conversation

@linus-skold
Copy link
Contributor

@linus-skold linus-skold commented Oct 10, 2025

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.rs but 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_regex function 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

body = """
{% if version %}\
    # [{{ version | trim_start_matches(pat="v") }}]
{% else %}\
    # [unreleased]
{% endif %}\
{% for group, commits in commits | group_by(attribute="group") %}
    {% if group == "Others" %}
        ## {{ group | striptags | trim }}\
    {% else %}
        {{ group | striptags | trim }}\
    {% endif %}
    {% for commit in commits %}
      {% set issues = commit.message | find_regex(pat="#\\d+")   %}\
      {% for issue in issues | slice(start=1) %}\
        {{issue}}\n
      {% endfor %}
      {% set message = commit.message | split(pat="\n") %}
      {% if message | length > 1 %}\
        - {{ message[0] | trim }}\
      {% endif %}
    {% endfor %}
{% endfor %}
"""

Screenshots / Logs (if applicable)

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (no code change)
  • Refactor (refactoring production code)
  • Other

Checklist:

  • My code follows the code style of this project.
  • I have updated the documentation accordingly.
  • I have formatted the code with rustfmt.
  • I checked the lints with clippy.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@linus-skold linus-skold requested a review from orhun as a code owner October 10, 2025 14:49
@welcome
Copy link

welcome bot commented Oct 10, 2025

Thanks for opening this pull request! Please check out our contributing guidelines! ⛰️

@codecov-commenter
Copy link

codecov-commenter commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 80.55556% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 44.18%. Comparing base (85cc05d) to head (0db734d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
git-cliff-core/src/template.rs 80.56% 7 Missing ⚠️
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     
Flag Coverage Δ
unit-tests 44.18% <80.56%> (+0.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ognis1205
Copy link
Contributor

cc: @orhun

I’d love to hear @dslemusp ’s perspective on this PR as well — their insight would be really valuable here.

Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@linus-skold
Copy link
Contributor Author

@orhun Super good point, would be rather confusing to use otherwise.
Added the examples

@orhun
Copy link
Owner

orhun commented Nov 4, 2025

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]
  ```

@linus-skold
Copy link
Contributor Author

@orhun Fixed!

Copy link
Owner

@orhun orhun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@orhun orhun merged commit 8270084 into orhun:main Nov 4, 2025
91 checks passed
@welcome
Copy link

welcome bot commented Nov 4, 2025

Congrats on merging your first pull request! ⛰️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants