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

[Question] How to generate changelog by conventional commits? #727

Open
moecasts opened this issue Dec 31, 2021 · 6 comments
Open

[Question] How to generate changelog by conventional commits? #727

moecasts opened this issue Dec 31, 2021 · 6 comments

Comments

@moecasts
Copy link

Affected Packages

@changesets/cli

Problem

Now, I have a repo with some angular conventional commits, and I want to switch to changesets, how can I automatically generate some changelogs for each packages?

eg: https://github.com/conventional-changelog/conventional-changelog

Proposed solution

Automatically generate by conventional commits

@Andarist
Copy link
Member

There is currently no automatic way to do this - but a script could be written to do this. How would one know when the last release has happened? How to limit the range of the commits that should be "converted" to changeset files?

@bastienrobert
Copy link

bastienrobert commented Apr 11, 2022

I think it could be possible to add a new conventional-changelog package which could format conventional commits following their types. The range of the commits that should be "converted" will be defined by default in the package (cf. conventional-changelog) and could be edited in an object of types, eg. .changeset/config.json:

{
  "changelog": [
    "@changesets/conventional-changelog",
    { 
      "types": {
        // TYPE/TYPES: commit type(s) prefix
        // SECTION: title generated in the changelog
        { types: ["feat", "feature"], section: "Features" },
        { type: "fix", section: "Bug Fixes" },
      }
    }
  ]
}

Also, it might be possible to add a "strict" option that is disabled by default, which would remove commits that do not respect the convention. If disabled there would be a fallback on the current sections (major, minor and patch).

A new getReleaseLines function should run so that you can reorder the lines here:

return [
`## ${release.newVersion}`,
await generateChangesForVersionTypeMarkdown(changelogLines, "major"),
await generateChangesForVersionTypeMarkdown(changelogLines, "minor"),
await generateChangesForVersionTypeMarkdown(changelogLines, "patch")
]
.filter(line => line)
.join("\n");

@tjmgregory
Copy link

tjmgregory commented Apr 23, 2022

Would love for this as a feature - is the only thing keeping us on lerna-lite. As a team we're pretty hot on using conventional for all our commits (wips included), so ideally our workflow would be to merge the branch as is and for highest commit's type to be used as the version bump and then all commits bundled to the appropriate sections of the changelog :)

@jayalfredprufrock
Copy link

I think a good compromise that might reduce complexity would be to add a flag to the changeset command that reads in all unpushed commits into the generated changeset file, and perhaps throw an error on unstaged files. Then you could still modify the changeset file manually to clarify/improve the changelog messaging. Ideally this command would also stage the changeset file as well. So then if you are following conventional commits, you only need to run the changeset command once directly before pushing. Seems doable as an external script, but seems like the community could benefit from something along these lines and seems within scope.

@jindong-zhannng
Copy link

Any update?

@moecasts
Copy link
Author

moecasts commented Feb 1, 2024

Any update?

@jindong-zhannng this script is work for me.
https://github.com/moecasts/casts-design/blob/main/packages/casts-cli/src/cli-changesets.ts

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

6 participants