Skip to content

Commit footers have values but no names #96

@hawkw

Description

@hawkw

Describe the bug

When a conventional commit has footers (such as Signed-off-by: Someone <email>), the footers 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 add Signed-off-by emails to a changelog entry, but not Reviewed-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 changing commit.footers from an array to a map of footer names to footer values.

System

  • OS Information:

    :; uname -a
    Linux noctis 5.17.3 #1-NixOS SMP PREEMPT Wed Apr 13 17:27:43 UTC 2022 x86_64 GNU/Linux
    
  • Project Version:

    :; git-cliff --version
    git-cliff 0.7.0
    

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 calls f.value():

&conv
.footers()
.to_vec()
.iter()
.map(|f| f.value())
.collect::<Vec<&str>>(),

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?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions