-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
feat(commit)!: pass footer token and separator to template #97
Conversation
Currently, when a conventional commit has footers, only the footers' values (the part after the separator token, such as `:`) are passed to the template. This means that when multiple footers, such as `Signed-off-by:` and `Co-authored-by:` are present, it isn't currently possible for the template to determine the name of the footer. This makes actually using data from footers in templates impractical in most cases. This commit fixes this by changing the `Serialize` impl for `Commit` to pass the commit's footers as a structured object rather than a string. The structured `Footer` type includes the footer's token (which is what `git_conventional` calls the name preceding the separator token), the separator, and the value. I didn't make the new `Footer` type and `Commit::footers` method public, because it isn't strictly necessary to add them to the `git-cliff-core` public API to fix this issue. However, we can make them public in a follow-up PR if this is considered useful. Fixes orhun#96 BREAKING CHANGE: This changes type of the `commit.footers` array exposed to templates. Currently, when a template uses `commit.footers`, it can treat the values as strings. After this change, the footer object will need to have its fields unpacked in order to use them. However, the impact of this breakage is probably not that severe, since it's not really practical to use footers in templates with the current system.
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Codecov Report
@@ Coverage Diff @@
## main #97 +/- ##
==========================================
+ Coverage 40.15% 43.40% +3.26%
==========================================
Files 15 15
Lines 969 1007 +38
Branches 252 252
==========================================
+ Hits 389 437 +48
+ Misses 456 444 -12
- Partials 124 126 +2
Continue to review full report at Codecov.
|
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.
Had a couple of nitpicks here and there but looks great! 💯
Can you also add test fixtures for this change as well? I might do it after merge if you don't want to include in the PR, no problem.
Ah, also include this change in the PR please. It seems like a good way to demonstrate how footers can be used within template. |
Hey @hawkw, can you take a look at this PR soon? I would like to include it in the next release of |
Sorry, I didn't have a chance to follow up sooner. I'll go ahead and address the remaining feedback, thanks! |
Sure, happy to do that! One quick question, though: is there an example repository you're using to generate the example changelogs in the README? I would want to re-generate the "detailed" example now that the template has changed. |
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
I added some tests for commits with footers in git-cliff/git-cliff-core/src/commit.rs Lines 354 to 404 in 9f78b0c
Are there other tests you're referring to? I'm happy to add any other tests that are necessary for this change, but I wasn't sure where else you would want to test this. |
Ah, good point. I made it public: https://github.com/orhun/git-cliff-readme-example |
Yup, it looks good 👍🏼
There are fixture tests in |
Oh, I see, I missed those. I'll figure out how to add those tests as well. |
I just added fixture tests and made some tweaks to the |
Description
This branch changes the
Serialize
impl forCommit
to output conventionalcommit footers as structured JSON objects, rather than as just the footer's
value string.
See hawkw/git-cliff@93779b2 for a discussion of
the implementation details of this change.
Motivation and Context
As discussed in issue #96, using footers in changelog templates is currently not
practical in most cases, since there is currently no way to determine which
footer a value belongs to, and no way to access the name of the footer.
This PR implements the approach suggested by @orhun in #96 (comment).
Additionally, I added a section to the README documentation discussing the
structure of the footers passed to templates.
Fixes #96
How Has This Been Tested?
I added a new test in
commit.rs
that conventional commits with footers have afooters
iterator containing the correct footers. In addition, I did somemanual testing to test the use of footers in templates --- see the next section
for details.
Screenshots / Output (if appropriate):
To manually verify that everthing works end-to-end, I temporarily modified
examples/detailed.toml
to output footers in the template:Generating a test changelog with that template now outputs footers, as expected:
Types of changes
Checklist: