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

Support creating the changelog based on pull requests only

Open landerss1 opened this issue 1 year ago • 3 comments
trafficstars

Is there an existing issue or pull request for this?

  • [X] I have searched the existing issues and pull requests

Feature description

It's very common to use branch protection rules with GitHub to require a pull request before merging. With this in place, it's actually not that relevant to use the individual commits to create the changelog. Instead, you would rather use the PR titles alone with the commit-parsers to get the group, scope and so on. However, currently there is no support for doing this as

  1. You can not limit the commits to pull requests only
  2. The commit parsers don't allow parsing the pr_title attribute (maybe they do, but as not all commits are pull requests it doesn't work)

Desired solution

When using GitHub, add a config flag that allows you to fetch only pull requests, e.g pull_requests_only = true. Furthermore, allow the commit parsers to use the pr_title field instead of the message field to set the group and scope.

Alternatives considered

Have tried pre-processing to modify the commit message, but sometimes there's a lot of commit messages in there when there's an associated PR, and it makes it very hard to make any sense of the contents of the message.

Additional context

No response

landerss1 avatar May 26 '24 15:05 landerss1

I think adding a new configuration option for this might be too much.

Instead, you can simply achieve this by filtering by the github attribute in the template. For example:

{% if commit.github.pr_number %}
  [#{{ commit.github.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.github.pr_number }})
{%- endif -%}

The commit parsers don't allow parsing the pr_title attribute (maybe they do, but as not all commits are pull requests it doesn't work)

The example I gave above will likely work in this case because we are checking if the pr_number exists.

Hope this helps! 🐻

orhun avatar May 26 '24 20:05 orhun

I'm already using the suggested technique to filter out the commits, but it doesn't solve the case where the commit message don't allow me to use a parser to group them properly. So my fallback now is to use a catch all and assign a miscellaneous group, but the result is that PR:s that clearly should have a different group now end up in the miscellaneous group. If I could use the pr_title for the parser it wouldn't be a problem.

landerss1 avatar May 27 '24 06:05 landerss1

Can you share some example commits and snippet from your configuration (especially commit_parsers)?

If I could use the pr_title for the parser it wouldn't be a problem.

That would be straightforward to implement actually 🤔

orhun avatar May 27 '24 18:05 orhun

I'm also interested in this one, we have the exact same problem.

We would like to mimic what Githubs built-in changelog generator does, which is to to list only the PRs, with the titles and some other metadata, grouped based on a label.

https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes

sandstrom avatar Oct 28 '24 21:10 sandstrom

This should be now possible after #758 (simply use github.pr_title for the parser)

See https://git-cliff.org/blog/2.5.0#-grouping-by-arbitrary-fields

orhun avatar Oct 29 '24 07:10 orhun

@orhun Awesome! 😄

sandstrom avatar Oct 29 '24 10:10 sandstrom

That's good news. Thanks!

landerss1 avatar Nov 01 '24 13:11 landerss1