Skip to content

Instantly share code, notes, and snippets.

@joseph-henry
Created May 13, 2019 22:53
Show Gist options
  • Save joseph-henry/7d43379ffa39db1af99903fd9fe6c84d to your computer and use it in GitHub Desktop.
Save joseph-henry/7d43379ffa39db1af99903fd9fe6c84d to your computer and use it in GitHub Desktop.
Generate markdown CHANGELOG from git-log with included comparison links
#!/bin/bash
generate_changelog()
{
github_user="user"
github_project_name="project"
first_commit=$(git rev-list --max-parents=0 HEAD)
git for-each-ref --sort=-refname --format="## [%(refname:short)] - %(taggerdate:short) &(newline)*** &(newline)- %(subject) %(body)" refs/tags > CHANGELOG.md
gsed -i '''s/\&(newline)/\n/' CHANGELOG.md # replace first instance
gsed -i '''s/\&(newline)/\n/' CHANGELOG.md # replace second instance
echo -e "\n" >> CHANGELOG.md
for curr_tag in $(git tag -l --sort=-v:refname)
do
prev_tag=$(git describe --abbrev=0 ${curr_tag}^)
if [ -z "${prev_tag}" ]
then
prev_tag=${first_commit}
fi
echo "[${curr_tag}]: https://github.com/${github_user}/${github_project_name}/compare/${prev_tag}..${curr_tag}" >> CHANGELOG.md
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment