Skip to content
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

Merge commits not appearing in the changelog commits list #254

Open
aclarkot opened this issue Feb 17, 2023 · 5 comments
Open

Merge commits not appearing in the changelog commits list #254

aclarkot opened this issue Feb 17, 2023 · 5 comments

Comments

@aclarkot
Copy link

When I create a pull request and perform a Squash and Merge, the merge commit for the PR is not showing up in the changelog after running auto-changelog.

I've been trying to troubleshoot why that is but can't find any reason for it. The PR commit message matches the regular commit pattern that is working. Only regular commits on master are being added to the changelog.

I assume there's something unique about the PR merge commit that means it gets ignored. GitHub appends a PR number at the end of the commit message and adds some additional 'co-author' details.

Anyone else experienced this issue and know how to fix it?

@aclarkot
Copy link
Author

I'm not using the standard handlebars template, so I guess it's something to do with that. There is no {{#if merges}} section, I guess it could be to do with that.

# Changelog

All notable changes to this project will be documented in this file.

{{#each releases}}
{{#if href}}
  ## [{{title}}]({{href}})
  {{#if tag}}
    > {{isoDate}}
  {{/if}}
{{else}}
  ## {{title}}
  {{#if tag}}
    > {{isoDate}}
  {{/if}}
{{/if}}
{{#if summary}}
  {{summary}}
{{/if}}

{{#commit-list
  commits
  heading='### :rocket: Features'
  message='(feat)|(Feat)|(feature)|(Feature)'
  excludes='(fix)|(Fix)'}}
* {{subject}} ([`{{shorthash}}`]({{href}})) : {{author}}
{{/commit-list}}

{{#commit-list
  commits
  heading='### :wrench: Fixes'
  message='(fix)|(Fix)'
  excludes='(feat)|(Feat)|(feature)|(Feature)'}}
* {{subject}} ([`{{shorthash}}`]({{href}})) : {{author}}
{{/commit-list}}

{{#commit-list
  commits
  heading='### :bulb: Other'
  message=''
  exclude='(fix)|(Fix)|(feat)|(Feat)|(feature)|(Feature)'}}
* {{subject}} ([`{{shorthash}}`]({{href}})) : {{author}}
{{/commit-list}}

{{/each}}

@aclarkot
Copy link
Author

OK merges are now being included in the changelog after adding the section for the keepchangelog.hbs template in this repo.

{{#if merges}}
  {{#each merges}}
    - {{#if commit.breaking}}**Breaking change:** {{/if}}{{message}} {{#if href}}[`#{{id}}`]({{href}}){{/if}}
  {{/each}}
{{/if}}

There are in a separate section and not listed along the regular 'Features' and 'Fixes' commit-list though.

@aclarkot
Copy link
Author

aclarkot commented Feb 18, 2023

OK so after running:

auto-changelog --template json --output changelog-data

It's clear that merges and commits are separate objects and the merge.commit is not part of the commits list.

This is a pain when using Trunk based development and squash merges, as generally there will be no direct commits on master and only merge commits. So, I'd like to have the commit-list helper process the merge commits too. Hence it would be good if auto-changelog had an option such as --include-merge-commits to optionally add all the merge commits into the overall commits list. 'Git log' shows all the commits is a single list so I'm not sure way you'd choose to exclude merge commits from commits in the changelog-data.

In the meantime, seems I'll just have to accept having a simple Merges list without any of the logic to categorize merge commits like with the commit-list helper.

@aclarkot aclarkot changed the title Github pull request merge commits not appearing in the changelog Github merge commits not appearing in the changelog commits list Feb 18, 2023
@aclarkot aclarkot changed the title Github merge commits not appearing in the changelog commits list Merge commits not appearing in the changelog commits list Feb 18, 2023
@WenLonG12345
Copy link

I'm not using the standard handlebars template, so I guess it's something to do with that. There is no {{#if merges}} section, I guess it could be to do with that.

# Changelog

All notable changes to this project will be documented in this file.

{{#each releases}}
{{#if href}}
  ## [{{title}}]({{href}})
  {{#if tag}}
    > {{isoDate}}
  {{/if}}
{{else}}
  ## {{title}}
  {{#if tag}}
    > {{isoDate}}
  {{/if}}
{{/if}}
{{#if summary}}
  {{summary}}
{{/if}}

{{#commit-list
  commits
  heading='### :rocket: Features'
  message='(feat)|(Feat)|(feature)|(Feature)'
  excludes='(fix)|(Fix)'}}
* {{subject}} ([`{{shorthash}}`]({{href}})) : {{author}}
{{/commit-list}}

{{#commit-list
  commits
  heading='### :wrench: Fixes'
  message='(fix)|(Fix)'
  excludes='(feat)|(Feat)|(feature)|(Feature)'}}
* {{subject}} ([`{{shorthash}}`]({{href}})) : {{author}}
{{/commit-list}}

{{#commit-list
  commits
  heading='### :bulb: Other'
  message=''
  exclude='(fix)|(Fix)|(feat)|(Feat)|(feature)|(Feature)'}}
* {{subject}} ([`{{shorthash}}`]({{href}})) : {{author}}
{{/commit-list}}

{{/each}}

Thanks for this useful template! And it is very nice!

@splincode
Copy link

I use my approach

Handlebars.registerHelper('commit-parser', function (merges, commits, options) {
        const commitsFromMerges = merges.map((merge) => merge.commit);
        const result = commits.concat(commitsFromMerges);

        return options.fn(result);
    });
# Changelog

All notable changes to this project will be documented in this file. See
[standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.


{{#each releases}}
    {{#if tag}}
     ##{{#unless major}}#{{/unless}} [{{#replaceTitle}}{{title}}{{/replaceTitle}}]({{href}}) ({{isoDate}})
    {{/if}}

  {{#if summary}}
    {{summary}}
  {{/if}}

  {{#commit-parser merges commits}}

      {{#commit-list this heading='### ⚠ BREAKING CHANGES' message='[bB]reaking [cC]hange:|[bB]reaking:' }}
        - {{#replaceCommit}}{{subject}}{{/replaceCommit}} [({{shorthash}})]({{href}})
      {{/commit-list}}

      {{#commit-list this heading='### 🚀 Features' message='^[fF]eat:|[fF]eat\(|^[rR]efactor:|^[rR]efactor\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
        - {{#replaceCommit}}{{subject}}{{/replaceCommit}} [({{shorthash}})]({{href}})
      {{/commit-list}}

      {{#commit-list this heading='### 🐞 Bug Fixes' message='^[fF]ix:|^[fF]ix\(|^[pP]erf:|^[pP]erf\(' exclude='[bB]reaking [cC]hange:|[bB]reaking:'}}
        - {{#replaceCommit}}{{subject}}{{/replaceCommit}} [({{shorthash}})]({{href}})
      {{/commit-list}}

  {{/commit-parser}}

{{/each}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants