git-cliff icon indicating copy to clipboard operation
git-cliff copied to clipboard

feat: add tera filter for ordered commit groups

Open robjtede opened this issue 2 years ago • 7 comments

Description

Add a Tera filter that produces commit groups, with order determined by commit_parsers config.

At least, that is the end goal, the PR does not yet achieve this. It's definitely a mess but I'd like some feedback on the overall goal before progressing further.

Motivation and Context

Using group_by(attribute="group") may not produce desired behavior if order of changelog section matters, eg. "Features" before "Bug Fixes".

As far as I can tell, the most sensible place to source the ordering details is the commit_parsers config (it's what I initially tried to force sections to be ordered differently). It's not wired up like that yet, but hopefully this half of the task shows that it can be done.

How Has This Been Tested?

A new integration test has been added showing that ordering of sections is definable and not accidentally determined by the hash in a regular map.

Screenshots / Logs (if applicable)

Types of Changes

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

Checklist:

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

robjtede avatar Nov 05 '23 14:11 robjtede

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

welcome[bot] avatar Nov 05 '23 14:11 welcome[bot]

This looks good, the question is how can we naturally support this in a non-breaking way. As far as I understood, the user needs to use commit_groups(groups=commit_groups_filter) rather than group_by(attribute="group"). Is that enough? Can you provide more information?

orhun avatar Nov 14 '23 14:11 orhun

Yea idea of the non-breaking path is to require a different filter. The current groupBy behavior would remain the same.

robjtede avatar Nov 14 '23 14:11 robjtede

Cool, how far are we from implementing that? I'm not sure if I quite understood the contents of this PR - are you planning to make that happen?

orhun avatar Nov 14 '23 14:11 orhun

It's def not done in the PR yet. You can see the test case for a lil peek at what the PR currently does.

The goal is:

- {% for group, commits in commits | group_by(attribute="group") %}
+ {% for group, commits in commits | commit_groups %}

I'm not 100% sure if it's possible to do it without extra args to the new filter yet.

robjtede avatar Nov 14 '23 14:11 robjtede

I looked into Tera internals and I don't think it is possible to pass an argument to a filter. But as a workaround we can use a static global variable.

I took a stab at this at commit-groups-filter-improved branch. Especially this commit makes it possible to call commit_groups without args.

Let me know if you think this is applicable and we can work on polishing the implementation.

orhun avatar Dec 04 '23 20:12 orhun

ping 🐻

orhun avatar Dec 06 '23 18:12 orhun

closing for now, I might come back to this in the future

orhun avatar Mar 24 '24 20:03 orhun