Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate changelog from commit and tag

I'm trying to generate changelog to a project (repo in bitbucket.org), but I can't find an easy solution. We are using this pattern

(<type>(<scope>): <subject>)

to fill the commit messages, and tags to version (0.1, 0.2, 0.3).

Is there anything out-of-the-box (some script, npm package, etc...) or the best thing I can do is write some custom script using git log and parse the data (commit messages, etc...)?

I know there is an github-changelog-creator, but I can't use as long as this repo is in a bitbucket repo.

like image 623
Christian Benseler Avatar asked Nov 29 '16 12:11

Christian Benseler


People also ask

How do I make changelog automatically?

Auto-Generate ChangelogFollow the Conventional Commits Specification in your repository. We will use @commitlint/config-conventional to enforce this via Git hooks. Use standard-version, a utility for versioning using SemVer and changelog generation powered by Conventional Commits.

What is conventional changelog?

conventional-changelog: a set of tools for parsing Conventional Commits messages from git histories. parse-commit-message: Extensible utilities for parsing, stringify and validating Conventional Commit messages.


1 Answers

We are using this simple shell script to generate hierarchical change log sorted by tags with the latest tag on top.

#!/usr/bin/env bash
previous_tag=0
for current_tag in $(git tag --sort=-creatordate)
do

if [ "$previous_tag" != 0 ];then
    tag_date=$(git log -1 --pretty=format:'%ad' --date=short ${previous_tag})
    printf "## ${previous_tag} (${tag_date})\n\n"
    git log ${current_tag}...${previous_tag} --pretty=format:'*  %s [View](https://bitbucket.org/projects/test/repos/my-project/commits/%H)' --reverse | grep -v Merge
    printf "\n\n"
fi
previous_tag=${current_tag}
done

And you can put it in the project root as some shel file and run it (depending upon your platform you might need to make it executable) as below

sh change-log-builder.sh > changelog.md

And the resulting changelog.md looks like this


v1.1.0 (2017-08-29)

  • Adds IPv6 support [View]
  • Adds TreeMaker class and its test. [View]

v1.0.9 (2017-08-22)

  • Updates composer.json.lock [View]

v1.0.8 (2017-08-22)

  • Adds S3Gateway as substitute class [View]
  • Removes files no more used [View]
like image 76
Waku-2 Avatar answered Oct 24 '22 21:10

Waku-2