Last active
November 1, 2023 08:03
-
-
Save seunggabi/8fa40a3585d37519db5beab5f0563766 to your computer and use it in GitHub Desktop.
prepare-commit-msg
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
#!/bin/bash | |
if [ -z "${SKIP_BRANCH}" ]; then | |
SKIP_BRANCH=(master develop release hotfix) | |
fi | |
NAME=$(git symbolic-ref --short HEAD) | |
NAME="${NAME##*/}" | |
JIRA=`echo ${NAME} | egrep -o '.+-[0-9]+_' | egrep -o '.+-[0-9]+'` | |
ISSUE=`echo ${NAME} | egrep -o '#[0-9]+_' | egrep -o '#[0-9]+'` | |
EXCLUDED=$(printf "%s\n" "${SKIP_BRANCH[@]}" | grep -c "^${NAME}$") | |
PREFIX="" | |
if [[ -n ${JIRA} ]]; then | |
PREFIX="[${JIRA}] " | |
fi | |
if [[ -n ${ISSUE} ]]; then | |
PREFIX="${PREFIX}(${ISSUE}) " | |
fi | |
PREFIX_ESCAPE=`echo ${PREFIX} | sed -e 's/\[/\\\\[/g' | sed -e 's/\]/\\\\]/g'` | |
DONE=$(grep -c "${PREFIX_ESCAPE}" $1) | |
if ! [[ ${EXCLUDED} -eq 1 ]] && ! [[ ${DONE} -ge 1 ]]; then | |
sed -i.bak -e "1s/^/${PREFIX}/" $1 | |
fi |
New clean up codes.
#!/bin/bash
if [ -z "${SKIP_BRANCH}" ]; then
SKIP_BRANCH=(master develop release hotfix)
fi
NAME=$(git symbolic-ref --short HEAD)
NAME="${NAME##*/}"
JIRA=$(echo "${NAME}" | grep -E -o '.+-[0-9]+' | grep -E -o '.+-[0-9]+')
ISSUE=$(echo "${NAME}" | grep -E -o '#[0-9]+' | grep -E -o '#[0-9]+')
EXCLUDED=$(printf "%s\n" "${SKIP_BRANCH[@]}" | grep -c "^${NAME}$")
PREFIX=""
if [[ -n ${JIRA} ]]; then
PREFIX="[${JIRA}] "
fi
if [[ -n ${ISSUE} ]]; then
PREFIX="${PREFIX}(${ISSUE}) "
fi
PREFIX_ESCAPE=$(echo "${PREFIX}" | sed -e 's/[/\\[/g' | sed -e 's/]/\\]/g')
DONE=$(grep -c "${PREFIX_ESCAPE}" "$1")
if ! [[ ${EXCLUDED} -eq 1 ]] && ! [[ ${DONE} -ge 1 ]]; then
sed -i.bak -e "1s/^/${PREFIX}/" "$1"
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
start
example