Last active
October 14, 2019 14:31
-
-
Save shikaan/51ec4450b04fb874207aaa1246485782 to your computer and use it in GitHub Desktop.
Generate Changelogs with Conventional Commits
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 | |
tag= | |
branch= | |
tag_value= | |
branch_value= | |
has_options= | |
print_usage() { | |
name="$(basename $0)" | |
printf """ | |
Usage: | |
%s [options] /path/to/git/repo | |
Print changlelog for git repositories. | |
Options: | |
-t <tag>\tCompare current revision with specified tag | |
-b <branch>\tCompare current revision with specified branch | |
""" $name | |
} | |
# Transform long options to short ones | |
for arg in "$@"; do | |
shift | |
case "$arg" in | |
"--tag") set -- "$@" "-t" ;; | |
"--branch") set -- "$@" "-b" ;; | |
"--help") set -- "$@" "-h" ;; | |
*) set -- "$@" "$arg" | |
esac | |
done | |
while getopts "t:b:h" reference; | |
do | |
case $reference in | |
t) tag=1 | |
has_options=1 | |
tag_value="$OPTARG";; | |
b) branch=1 | |
has_options=1 | |
branch_value="$OPTARG";; | |
h | -) print_usage | |
exit 0;; | |
*) print_usage | |
exit 2;; | |
esac | |
done | |
shift $(($OPTIND - 1)) | |
path="$@" | |
if [ -z "$has_options" ]; | |
then | |
print_usage | |
exit 2 | |
fi | |
if [ -z "$path" ]; | |
then | |
echo "No path provided, defaulting to $(pwd)" | |
else | |
cd $path | |
fi | |
if [ ! -z "$tag" ]; | |
then | |
echo "## Bugfix" | |
git log --pretty=format:'* %s' --no-merges --grep fix: "refs/tags/$tag_value"..HEAD | |
echo "## Features" | |
git log --pretty=format:'* %s' --no-merges --grep feat: "refs/tags/$tag_value"..HEAD | |
exit 0 | |
fi | |
if [ ! -z "$branch" ]; | |
then | |
echo "## Bugfix" | |
git log --pretty=format:'* %s' --no-merges --grep fix: "refs/heads/$branch_value"..HEAD | |
echo "## Features" | |
git log --pretty=format:'* %s' --no-merges --grep feat: "refs/heads/$branch_value"..HEAD | |
exit 0 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment