release_notes() {
if [ -z "$1" ]; then
echo "Error: Provide a starting tag." >&2
return 1
fi
readonly TAG_BEGAN=$1
readonly TAG_ENDED=${2:-$(git describe --abbrev=0 --tags)}
readonly REPO_URL="https://repo.autonoma.ca/keenwrite.git"
readonly CURRENT_DATE=$(date +"%B %d, %Y")
if [ -z "$TAG_ENDED" ]; then
echo "Error: Could not determine end tag." >&2
return 1
fi
local tags_between
tags_between=$(git tag --sort=-version:refname --merged="$TAG_ENDED" | \
awk "/$TAG_ENDED/{found=1; print} found && /$TAG_BEGAN/{exit} found")
cat << EOF
$CURRENT_DATE
Changes between $TAG_BEGAN and $TAG_ENDED.
EOF
if [ -z "$tags_between" ]; then
local commits
commits=$(git log --pretty=format:'* [%h]('$REPO_URL'/commit/%H) -- %s' --reverse "$TAG_BEGAN".."$TAG_ENDED")
if [ -n "$commits" ]; then
echo "## $TAG_ENDED"
echo
echo "$commits"
echo
fi
return 0
fi
local next_tag="$TAG_ENDED"
tags_between=$(echo -e "$tags_between\n$TAG_BEGAN")
while IFS= read -r current_tag; do
[ -z "$current_tag" ] && continue
local commits
commits=$(git log --pretty=format:'* [%h]('$REPO_URL'/commit/%H) -- %s' --reverse "$current_tag".."$next_tag")
if [ -n "$commits" ]; then
echo "## $next_tag"
echo
echo "$commits"
echo
fi
next_tag="$current_tag"
done <<< "$tags_between"
}
release_notes "$@"