Last active
April 5, 2020 05:01
-
-
Save nikoheikkila/96f734a5dffa7a9e6e32c33e8b2c7ddc to your computer and use it in GitHub Desktop.
Fish Shell: Generate a clean changelog between two Git revisions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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