Skip to content

Instantly share code, notes, and snippets.

@joehillen
Created June 9, 2021 20:56
Show Gist options
  • Save joehillen/e34fd3a975beba931af46013ac4b93ba to your computer and use it in GitHub Desktop.
Save joehillen/e34fd3a975beba931af46013ac4b93ba to your computer and use it in GitHub Desktop.
Amend git commits with semversioner changes
#!/bin/bash -ex
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ $BRANCH == patch* || $BRANCH == bugfix* ]]; then
VER_TYPE=patch
elif [[ $BRANCH == feature* || $BRANCH == minor* ]]; then
VER_TYPE=minor
elif [[ $BRANCH == major* ]]; then
VER_TYPE=major
else
VER_TYPE=$1
fi
if [[ $VER_TYPE != "patch" && $VER_TYPE != "minor" && $VER_TYPE != "major" ]]; then
echo 'Argument required: Must be "minor", "patch", or "major"'
exit 1
fi
if [[ ! -f CHANGELOG.md ]]; then
cd "$(git rev-parse --show-toplevel)"
fi
semversioner add-change --type $VER_TYPE --description "$(git --no-pager show -s --format=%s)"
git add .changes/next-release/
git commit --amend --no-edit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment