Created
October 9, 2014 23:55
-
-
Save jfsiii/e40b028a04943225e770 to your computer and use it in GitHub Desktop.
Simple bash script to generate a changelog based on tags & commit messages
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
#!/usr/bin/env bash | |
function printCommitLine(){ | |
local FROM=$1 | |
local TO=$2 | |
if [ TO ]; then | |
git log $GIT_LOG_OPTS --format="$LOG_FORMAT_OPTS" $FROM..$TO | |
else | |
git log $GIT_LOG_OPTS --format="$LOG_FORMAT_OPTS" $FROM | |
fi | |
} | |
function printTitleLine(){ | |
local TAG=$1 | |
printf "\n" | |
echo "## [$TAG]($TAG_URL$TAG)" | |
} | |
if [ -e 'bower.json' ]; then | |
MANIFEST='bower.json' | |
elif [ -e 'package.json' ]; then | |
MANIFEST='package.json' | |
else | |
echo "Can't find package.json or bower.json" | |
exit 1 | |
fi | |
NAME=$(node -p "require('$MANIFEST').name") | |
TAG_URL="https://cgit.twitter.biz/$NAME/tag/?id=" | |
COMMIT_URL="https://cgit.twitter.biz/$NAME/commit/?id=%h" | |
GIT_LOG_OPTS="--no-merges" | |
LOG_FORMAT_OPTS=" * [%h]($COMMIT_URL) %s" | |
TAGS=$(git tags | grep '^\d\.\d\.\d' | sort -u -r) | |
PREV='HEAD' | |
FIRST=$(git rev-list --max-parents=0 HEAD) | |
for CTAG in ${TAGS[@]}; do | |
printTitleLine $PREV | |
printCommitLine $CTAG $PREV | |
PREV=$CTAG | |
done | |
printTitleLine $CTAG | |
printCommitLine $FIRST $CTAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment