Last active
November 12, 2015 19:55
-
-
Save natecavanaugh/22a191527ab18cc7e679 to your computer and use it in GitHub Desktop.
Create a cursory changelog from a git log
This file contains 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
# Generates a cursory changelog from all tags in a git log | |
# All params are optional. If the from param is empty, | |
# it will create a changelog from all tags | |
# | |
# @param from - the tag or git commit to start from | |
# @param to - the tag or git commit to end at | |
# @param title - a title to give the log if specifying the previous options | |
function generate_changelog { | |
local changes hash log log_title tag tags prev from="$1" to="$2" title nl=$'\n'; | |
if [[ -z "$from" ]]; then | |
tags=$(git for-each-ref --format='%(*committerdate:raw)%(committerdate:raw) %(refname) %(*objectname) %(objectname)' refs/tags | sort -n | awk '{ gsub("refs/tags/", "", $3); print $3; }'); | |
else | |
title="$3" | |
tags="$from..$to" | |
fi | |
for tag in $tags; do | |
[[ -n $prev ]] && hash="$prev..$tag" || hash="$tag"; | |
log_title="$title" | |
if [[ -z "$log_title" ]]; then | |
log_title=$(IFS=$'\n'; echo $(git log -n1 $tag --pretty=format:'%s - %cd' --date=short) | awk -F' - ' '{ "date -j -f \"%Y-%m-%d\" "$2" +\"%B %d, %Y\"" |getline d; print $1" - "d }'); | |
fi | |
log=$(echo "## $log_title$nl"; g log --pretty=format:'* %s' "$hash" | grep -ivE 'Merge branch|Source Format|Rebuild|Build files' | /usr/bin/grep -vE '^\* \d+\.\d+\.\d+$'; echo ""); | |
changes="${nl}${log}${nl}$changes"; | |
prev="$tag"; | |
done; | |
echo "$changes" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment