Last active
December 11, 2018 18:38
-
-
Save tylernhoward/0593a706d07b59e4bdd65373ac6bf8b3 to your computer and use it in GitHub Desktop.
Utility script to parse ticket number out of branch name
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
#!/bin/bash | |
### Contrast specific utility script | |
### - Automatically formats a commit message based on the Jira ticket found in the branch name | |
### ARG1 = "commit text", ARG2 = "-skip" flag | |
# get commit message from arg | |
if [[ $1 == "" ]]; then | |
echo "No commit message given. Try again: -> commit \"message\"" | |
exit 1; | |
else | |
message=$1; | |
fi | |
# store if skip flag | |
skipValidation=$2 | |
# get branch name | |
branch=$(git symbolic-ref --short HEAD) | |
# rip out 'CONTRAST-#####' | |
regex="^.[A-Z]{7}(-)[0-9]*" | |
# if we find a ticket in the branch name, try to commit | |
if [[ $branch =~ $regex ]]; then | |
ticket=$BASH_REMATCH | |
commit="$ticket $message" | |
if [[ $skipValidation != "-skip" ]]; then | |
read -p "Does this look good to commit? (y/n) -> \"$commit\"" confirm && [[ $confirm == [yY] ]] || exit 1; | |
fi | |
git commit -m "$commit" | |
else | |
echo "Branch with name: '$branch' is invalid." | |
exit 1; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
alias commit='bash ${CONTRAST_DIR}/contrast-commit.sh'