npm package

commits-to-changelog

Create an unopionated CHANGELOG.md from Git commit history (see Details)

hh lohmann <hh.lohmann@gmail.com>

Changelog

Last 5 changes - see CHANGELOG file for full list and details

Synopsis

CLI without parameters

commits-to-changelog

Parameters

no parameters

Settings

Default settings can be overwritten by key-value pairs in an object as value for a key “commits-to-changelog” in a package.json belonging to the repo for which a CHANGELOG.md should be created, e.g.

// package.json
{
  "version": "...",
  "commits-to-changelog": {
    "headerDefault": "Latest",
    "headerMerged": "Implement",
    "linesToReadme": 5
  },
  "dependencies": {
    "...": "..."
  }
}

Possible Settings

filterCommits

Array of RegExp: Filter out commits / commit types identified by a message matching one of the RegExps in the array

filterDefaults

Boolean: Filter out commit types that are rather not relevant for users by matching commit messages against RegExps /^bump version$/i, /^changelog$/i, /^dev:/i, /^[Hh]ousekeeping/i, /^planning/i, /[Rr]efactoring/i, /tests/i

headerDefault

String to use as header for listing commits that do not belong to a defined Git tag

headerMerged

String to use as header for listing Merged Branches with a commit message of the form Merge branch '<branch name>'

linesToReadme

Write defined number of lines from the start of CHANGELOG.md also to an existing section with heading “Changelog” (or “CHANGELOG” or any preferred case) in README.md

requireTag

Reject creating a Changelog if commits without associated Git tag exist

Returns

no return

Examples

Sample CHANGELOG.md

See the CHANGELOG.md of this project

Sample for optionally writing to a section “Changelog” in README.md

See the section Changelog in this file (cf. details for optional setting linesToReadme under Settings)

Merged Branches

Branches that were merged as an explicit commit (i.e. no fast-forward) are listed as indented blocks with the message of the merge commit as a title line, e.g.

* dddb03a (HEAD -> master, origin/master) fix/unclear-error
|\
| * f6f8cd1 Update error message
|/
* 4bd8518 Update token hash to include encoded user name

as

- fix/unclear-error
  - Update error message
- Update token hash to include encoded user name

If the merge’s commit message has the form Merge branch '<branch name>' it will be replaced by Include (results of) separate branch '<branch-name>', e.g.

* dddb03a (HEAD -> master, origin/master) Merge branch 'fix/unclear-error'
...

as

- Include (results of) separate branch 'fix/unclear-error'
...

Dependencies

none

Installation

CLIs should be installed systemwide (“global”). Strip off the -g parameter or replace it by a -D (as development dependency, -d for Bun) to explicitly restrict to a repo bounded usage.

Pick for your preferred package manager:

  npm i -g commits-to-changelog
  pnpm i -g commits-to-changelog
  bun i -g commits-to-changelog
  # For Yarn you should double check docs for your and / or
  # current Yarn version, newer versions do not treat `i package_name`
  # as an alias for `add ...` and exclude global installations
  yarn add commits-to-changelog

Details

The resulting CHANGELOG.md has the simple structure

# Changelog

## {groupheader} ({date})

- [{commit-subject}]({commit-link})
- [{commit-subject}]({commit-link})

## {groupheader} ({date})

- [{commit-subject}]({commit-link})
- [{commit-subject}]({commit-link})

(...)

where # Changelog is the title, a Markdown atx heading (i.e. using “#”) of level 1 with the text “Changelog”, followed by an empty line, and lists of commits that are grouped by

so that the applicable Git tag / package.json version or the headerDefault becomes the {groupheader} that together with the date of the Git tag or else the current date constitutes a Markdown heading of level 2 under which associated commits are listed as

Besides the existence and characteristics of Git tags, a possible package.json and Git remote defintions the actually resulting CHANGELOG.md can be shaped by Settings.

Source Code

Prior Work

The (initial) code here is forked from git-to-changelog, an already very good solution, but due to a hardwired search path ‘../../package.json’ - mimicking npm’s way of structuring a node_modules folder - not usable with pnpm, and while fixing this some other little things were changed / improved (see CHANGELOG) and made the initial little fix grow into an own project

License

References

CommonMark Spec: ATX headings

Conventional Commits

Git commmit subject

Git: diff

Git: Working with Remotes: Showing Your Remotes

git-to-changelog

Non-labeled SemVer

Endspacer: './markdown-assets/endspacer.png' missing - see https://hh-lohmann.github.io/html-endspacer
[top]