Last active
February 29, 2020 05:17
-
-
Save tomaszprasolek/1317b8aee502e5a956b9e4fdbe5ede29 to your computer and use it in GitHub Desktop.
Script add # symbol to Azure DevOps task number in the end of commit messages to last X commits (X passed by parameter)
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 | |
USAGE="USAGE: git azuredevops NUMBER_OF_COMMITS\nExample: git azuredevops 5" | |
show_usage () { | |
echo -e "\n$USAGE" | |
} | |
add_hash() { | |
echo "" | |
git filter-repo -f --refs HEAD~$1..HEAD --message-callback ' | |
lastWord = message.split()[-1] | |
def RepresentsInt(s): | |
try: | |
int(s) | |
return True | |
except ValueError: | |
return False | |
if RepresentsInt(lastWord): | |
return message.replace(lastWord, b"#" + lastWord) | |
else: | |
return message' | |
} | |
case $1 in | |
help | -h | "/?") | |
show_usage | |
exit 1 | |
esac | |
# Check if is integer | |
# https://unix.stackexchange.com/questions/151654/checking-if-an-input-number-is-an-integer | |
if ! [ "$1" -eq "$1" ] 2> /dev/null | |
then | |
echo ">>> Parameter must be an integer!" | |
show_usage | |
exit 1 | |
fi | |
echo "" | |
echo "You want to add # character to task numbers to last $1 commits." | |
# https://stackoverflow.com/questions/226703/how-do-i-prompt-for-yes-no-cancel-input-in-a-linux-shell-script | |
while true; do | |
read -p "Do you want to continue [y/n]? " yn | |
case $yn in | |
[Yy]* ) add_hash $1; break;; | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes [y] or no [n].";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment