-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
Commit footers have values but no names #96
Comments
Hello, thanks for submitting this issue and the detailed explanation! 🐻 I would like to go over the possible options that you suggested and talk about the pros and cons. 1. Single string solutionAccording to pub struct Footer<'a> {
token: FooterToken<'a>,
sep: FooterSeparator,
value: &'a str,
} (Note that all the fields are private.) So doing this would be enough: commit.serialize_field(
"footers",
&conv
.footers()
.to_vec()
.iter()
.map(|f| {
format!("{}{} {}", f.token(), f.separator(), f.value())
})
.collect::<Vec<String>>(),
)?; Although this looks like a feasible solution and the context is compatible with the previous versions of 2.
|
That's what I thought, too, thanks for the confirmation. The breaking change is kind of unfortunate, though, so I wanted to ask. I suppose a third option is to keep the existing |
I would say that |
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.
* fix(commit): pass footer token and separator to template 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 #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. * docs(README): discuss footers in README Signed-off-by: Eliza Weisman <eliza@buoyant.io> * docs(examples): Add footers to `detailed.toml` Signed-off-by: Eliza Weisman <eliza@buoyant.io> * refac(commit): address review feedback Signed-off-by: Eliza Weisman <eliza@buoyant.io> * docs(README): address README review feedback Signed-off-by: Eliza Weisman <eliza@buoyant.io> * refactor(example): update detailed example about newline issues * test(fixture): add test fixture for commit footers Co-authored-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
Describe the bug
When a conventional commit has footers (such as
Signed-off-by: Someone <email>
), thefooters
array provided to the changelog template contains the value (the part after the:
) but not the name of the footer. This makes it difficult to implement any kind of special templating based on the name of the footer. For example, if I want to addSigned-off-by
emails to a changelog entry, but notReviewed-by
, it's currently impossible to determine what commit footer that value came from.To Reproduce
In a repository where commits contain multiple footers with different names, create a template with
{{ commit.footers }}
in it somewhere. Note that only the values of the footer are output.Expected behavior
The entire footer (including the name) should be exposed to the template. This could either be by making each entry in the
commit.footers
array be the entire footer value, including both the name and the value after the colon, or by changingcommit.footers
from an array to a map of footer names to footer values.System
OS Information:
Project Version:
Additional context
While looking at the code for serializing commits as JSON, I noticed that the
Serialize
impl maps over the list of footers and callsf.value()
:git-cliff/git-cliff-core/src/commit.rs
Lines 221 to 226 in 7d0786c
Although I'm not familiar with the
git_conventional
crate's API, my assumption is that this is discarding the footer's name. :)I'm happy to open a PR changing this behavior, which I imagine would be fairly straightforward. The one design decision is what we should output instead: is it preferable to emit the footers as a map of footer name to footer value (which could break existing templates, but seems nicer), or as an array of the footer's name and value as a single string? Or, is there some other approach that I haven't thought of?
The text was updated successfully, but these errors were encountered: