Skip to content

Instantly share code, notes, and snippets.

@nikoheikkila

nikoheikkila/changes.fish

Last active Apr 5, 2020
Embed
What would you like to do?
Fish Shell: Generate a clean changelog between two Git revisions
function changes -d "Generate a Markdown changelog from conventional commits" -a target
# Use fallback variables if no arguments were given.
if test (count $argv) -eq 0
set target master
end
# Include commit message, author name, and the short hash in parentheses.
set -l log_format "%s (_%aN_) (%h)"
# Compare against HEAD (the latest commit).
set -l source "HEAD"
# Filter to commits that pass the conventional commit format.
# See: https://www.conventionalcommits.org/
set -l commit_filter "^[a-z]+(\([a-z]+\))?:\s.+"
# Prefix each line with '- ' to render a Markdown list.
set -l prefix '{print "- " $0}'
set -l next_release (git semver get)
# Write changelog header
echo -e "## Release `$next_release`\n"
echo -e "Write your release notes on this line.\n"
echo -e "### Changes"
# Fill and sort the actual changelog
git log --oneline --pretty=format:$log_format $source...$target \
| grep -E "$commit_filter" \
| sort -k1 \
| awk "$prefix"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment