1
0
Fork 0

fix(scripts): correct parsing of type-only messages

This commit is contained in:
Sean Sube 2022-04-02 11:55:58 -05:00
parent cb6c04708b
commit 27164c6b4e
1 changed files with 14 additions and 13 deletions

View File

@ -13,6 +13,7 @@ SCOPE_ALIAS=(
['README.md']='docs' # with extension matches raw filename, pre-filter ['README.md']='docs' # with extension matches raw filename, pre-filter
['README']='docs' # without extension matches subdir or filename post-filter ['README']='docs' # without extension matches subdir or filename post-filter
# build
['.codeclimate.yml']='build' ['.codeclimate.yml']='build'
['.eslintrc.json']='build' ['.eslintrc.json']='build'
['.github']='build' ['.github']='build'
@ -24,13 +25,13 @@ SCOPE_ALIAS=(
['Makefile']='build' ['Makefile']='build'
['renovate.json']='build' ['renovate.json']='build'
['tsconfig.json']='build' ['tsconfig.json']='build'
# deps
['package.json']='deps' ['package.json']='deps'
['yarn.lock']='deps' ['yarn.lock']='deps'
['vendor']='deps' ['vendor']='deps'
# docs
['LICENSE.md']='docs' ['LICENSE.md']='docs'
# image
['.dockerignore']='image' ['.dockerignore']='image'
['Dockerfile.alpine']='image' ['Dockerfile.alpine']='image'
['Dockerfile.stretch']='image' ['Dockerfile.stretch']='image'
@ -87,7 +88,7 @@ function filter_scope() {
function debug_log() { function debug_log() {
if [[ ! -z "${DEBUG:-}" ]]; if [[ ! -z "${DEBUG:-}" ]];
then then
echo "${@}" printf '%s\n' "${@}"
fi fi
} }
@ -122,25 +123,25 @@ MESSAGE_TYPE=""
if [[ "${MESSAGE_FILE}" == "-" ]]; if [[ "${MESSAGE_FILE}" == "-" ]];
then then
echo -n 'message body: ' printf 'message body: '
read -e MESSAGE_BODY read -e MESSAGE_BODY
else else
MESSAGE_BODY="$(cat ${MESSAGE_FILE})" MESSAGE_BODY="$(cat ${MESSAGE_FILE})"
fi fi
# split up default message into segments # split up the existing message into segments, if any are present
if [[ "${MESSAGE_BODY}" =~ [a-z]+\([a-z\/]+\)\:[\ ]+[-a-zA-Z0-9\.\(\)]+ ]]; if [[ "${MESSAGE_BODY}" =~ [a-z]+\([a-z\/]+\)\:[\ ]+[-a-zA-Z0-9\.\(\)]+ ]];
then then
debug_log "default message is already conventional" debug_log "message is already conventional"
exit 0 exit 0
elif [[ "${MESSAGE_BODY}" =~ [a-z]+(\(\))*\:[\ ]+[-a-zA-Z0-9\.\(\)]+ ]]; elif [[ "${MESSAGE_BODY}" =~ [a-z]+(\(\))*\:[\ ]+[-a-zA-Z0-9\.\(\)]+ ]];
then then
debug_log "default message is missing scope" debug_log "message is missing scope"
MESSAGE_TYPE="$(echo "${MESSAGE_BODY}" | sed 's/:.*$//' | sed 's/()//')" MESSAGE_TYPE="$(echo "${MESSAGE_BODY}" | sed 's/:.*$//' | sed 's/()//')"
MESSAGE_BODY="$(echo "${DEFAULT_MESSAGE}" | sed 's/^.*://' | sed 's/^[ ]*//')" MESSAGE_BODY="$(echo "${MESSAGE_BODY}" | sed 's/^.*://' | sed 's/^[ ]*//')"
debug_log "default type: ${MESSAGE_TYPE}" debug_log "message type: ${MESSAGE_TYPE}"
debug_log "default message: ${MESSAGE_BODY}" debug_log "message body: ${MESSAGE_BODY}"
fi fi
# git ls-files -m for modified but unstaged # git ls-files -m for modified but unstaged
@ -207,7 +208,7 @@ debug_log "message: $COMMIT_MESSAGE"
if [[ "${MESSAGE_FILE}" == "-" ]]; if [[ "${MESSAGE_FILE}" == "-" ]];
then then
echo "${COMMIT_MESSAGE}" > /dev/stdout printf '%s\n' "${COMMIT_MESSAGE}"
else else
echo "${COMMIT_MESSAGE}" > "${MESSAGE_FILE}" printf '%s' "${COMMIT_MESSAGE}" > "${MESSAGE_FILE}"
fi fi