Forked from bartoszmajsak/prepare-commit-msg.sh
Last active
March 4, 2020 10:50
Revisions
-
Lowess revised this gist
Mar 4, 2020 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ (MLE-297-Fix-naming-for-prometheus) $ ./prepare-commit-msg.sh 'Fix featureA in controller' [MLE-297] Fix featureA in controller -
Lowess revised this gist
Mar 4, 2020 . 1 changed file with 36 additions and 7 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,17 +1,46 @@ #!/bin/bash # This way you can customize which branches should be skipped when # prepending commit message. if [ -z "${BRANCHES_TO_SKIP}" ]; then BRANCHES_TO_SKIP=(master develop stage test) fi if [ -z "${ENFORCE_JIRA_PATTERN}" ]; then ENFORCE_JIRA_PATTERN=0 fi # Grab the current branch name BRANCH_NAME=$(git symbolic-ref --short HEAD) # Strip any Gitflow prefix like hotfix/ bugfix/ feature/ BRANCH_NAME="${BRANCH_NAME##*/}" # Attempt to detect Jira project and ticket number format from the branch name BRANCH_PROJECT="${BRANCH_NAME%%-*}" _BRANCH_REMAINING="${BRANCH_NAME##"${BRANCH_PROJECT}-"}" BRANCH_TICKET="${_BRANCH_REMAINING%%-*}" JIRA_PREFIX="${BRANCH_PROJECT}-${BRANCH_TICKET}" JIRA_PROJECT_REGEX='^[A-Z]{2,10}-[0-9]{1,5}$' # Check if the branch is part of excluded ones BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -s -c "^$BRANCH_NAME$") # Check if the branch name is already in commit BRANCH_IN_COMMIT=$(echo "${1}" | grep -c "\\[${BRANCH_NAME}\\]") JIRA_IN_COMMIT=$(echo "${1}" | grep -c "\\[${JIRA_PREFIX}\\]") if [ -n "${BRANCH_NAME}" ] \ && ! [[ ${BRANCH_EXCLUDED} -eq 1 ]] \ && ! [[ ${BRANCH_IN_COMMIT} -ge 1 ]] \ && ! [[ ${JIRA_IN_COMMIT} -ge 1 ]]; then if [[ "${BRANCH_PROJECT}-${BRANCH_TICKET}" =~ ${JIRA_PROJECT_REGEX} ]] ; then echo "${1}" | sed -e "s/^/[${JIRA_PREFIX}] /" else # When JIRA pattern is enforced fail pre-commit on purpose if [[ ${ENFORCE_JIRA_PATTERN} -eq 1 ]]; then exit 1 else echo "${1}" | sed -e "s/^/[${BRANCH_NAME}] /" fi fi fi -
bartoszmajsak revised this gist
Oct 15, 2014 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,14 +2,16 @@ # This way you can customize which branches should be skipped when # prepending commit message. if [ -z "$BRANCHES_TO_SKIP" ]; then BRANCHES_TO_SKIP=(master develop test) fi BRANCH_NAME=$(git symbolic-ref --short HEAD) BRANCH_NAME="${BRANCH_NAME##*/}" BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$") BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1) if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_EXCLUDED -eq 1 ]] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1 fi -
bartoszmajsak revised this gist
Sep 22, 2014 . 1 changed file with 5 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,15 @@ #!/bin/bash # This way you can customize which branches should be skipped when # prepending commit message. DEFAULT_BRANCHES_TO_SKIP=(master develop test) if [ -z "$BRANCHES_TO_SKIP" ]; then BRANCHES_TO_SKIP=$DEFAULT_BRANCHES_TO_SKIP fi BRANCH_NAME=$(git symbolic-ref --short HEAD) if [ -n "$BRANCH_NAME" ] && ! [[ ${BRANCHES_TO_SKIP[*]} =~ $BRANCH_NAME ]]; then BRANCH_NAME=${BRANCH_NAME##*/} sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1 fi -
bartoszmajsak renamed this gist
Sep 19, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bartoszmajsak renamed this gist
Sep 19, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ # This way you can customize which branches should be skipped when # prepending commit message. if [ -z "$BRANCHES_TO_SKIP" ]; then BRANCHES_TO_SKIP=("master" "develop" "test") fi BRANCH_NAME=$(git symbolic-ref --short HEAD) -
bartoszmajsak revised this gist
Sep 19, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ #!/bin/sh # This way you can customize which branches should be skipped when # prepending commit message. if [ -z "$BRANCHES_TO_SKIP" ]; then BRANCHES_TO_SKIP=("master" "develop" "test") fi -
bartoszmajsak revised this gist
Sep 19, 2014 . 1 changed file with 9 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,14 @@ #!/bin/sh # This way you can customize which branches should be skipped when # preperending commit message. if [ -z "$BRANCHES_TO_SKIP" ]; then BRANCHES_TO_SKIP=("master" "develop" "test") fi BRANCH_NAME=$(git symbolic-ref --short HEAD) if [ -n "$BRANCH_NAME" ] && ! [[ ${BRANCHES_TO_SKIP[*]} =~ $BRANCH_NAME ]]; then BRANCH_NAME=${BRANCH_NAME##*/} sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1 fi -
bartoszmajsak revised this gist
Sep 18, 2014 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,5 +2,6 @@ BRANCH_NAME=$(git symbolic-ref --short HEAD) if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then BRANCH_NAME=${BRANCH_NAME##*/} sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1 fi -
bartoszmajsak revised this gist
Nov 25, 2013 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/sh BRANCH_NAME=$(git symbolic-ref --short HEAD) if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then sed -i.bak -e "1s/^/[$BRANCH_NAME] /" $1 fi -
bartoszmajsak renamed this gist
Nov 7, 2012 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
bartoszmajsak revised this gist
Dec 13, 2011 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/bin/sh BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *') if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_NAME" != "master" ]; then echo "[$BRANCH_NAME] $(cat $1)" > $1 fi -
bartoszmajsak created this gist
Nov 26, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ #!/bin/sh BRANCH_NAME=$(git branch 2>/dev/null | grep -e ^* | tr -d ' *') if [ -n "$BRANCH_NAME" ]; then echo "[$BRANCH_NAME] $(cat $1)" > $1 fi